// ==UserScript== // @name 视频倍速快捷键 // @version 0.3 // @description speed up/down video // @author BlueSky // @match *://*.bilibili.com/* // @match *://*.netflix.com/* // @match *://*.youtube.com/* // @grant none // @namespace https://greasyfork.org/users/447360 // @downloadURL none // ==/UserScript== (function () { 'use strict'; let title = '' let rate = 1 let selectors = [] if (/bilibili/.test(location.hostname)) { selectors = [ 'div.bilibili-player-video-top-title', 'span.tit' ] } else if (/netflix/.test(location.hostname)) { selectors = ['.ellipsize-text h4'] } else if (/youtube/.test(location.hostname)) { selectors = [ 'h1 > yt-formatted-string.style-scope.ytd-video-primary-info-renderer', '.ytp-title-link.yt-uix-sessionlink.ytp-title-fullerscreen-link' ] } let init_title_failed_count = 0 function initTitle() { for (const selector of selectors) { const el = document.querySelector(selector) if (el) { if (!title && el.innerText) { title = el.innerText console.debug('title:', title) return } } } if (!title && init_title_failed_count < 100) { console.debug('wait for title') setTimeout(initTitle, 100) init_title_failed_count++ } } initTitle() window.addEventListener('keydown', (e) => { if (e.key === '=' && rate < 16) { rate += 0.5 } else if (e.key === '-' && rate > 0.5) { rate -= 0.5 } else if (e.key === ']' && rate < 16) { rate += 0.25 } else if (e.key === '[' && rate > 0.25) { rate -= 0.25 } else if (e.key === '`') { rate = 0.5 } else { if (!(/youtube/.test(location.hostname))) { if (e.key === '1') { rate = 1 } else if (e.key === '2') { rate = 2 } else if (e.key === '3') { rate = 3 } else if (e.key === '4') { rate = 4 } else { return } } else { return } } setVideoRate() setVideoTitle() }) function setVideoRate() { console.debug(`rate: ${rate}x`) document.querySelector('video').playbackRate = rate } function setVideoTitle() { for (const selector of selectors) { const el = document.querySelector(selector) if (el) { el.innerText = `[${rate}x] ${title}` } } } })();