// ==UserScript== // @name YouTube 长按右方向键二倍速播放 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 在 YouTube 上长按右方向键时启用二倍速播放功能,并禁用默认的快进行为 // @author Sulley-naer // @license MIT // @match https://www.youtube.com/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; let isLongPress = false; let longPressTimer; let video; function enable2xPlayback() { if (video.playbackRate === 1) { video.playbackRate = 2; } else { video.playbackRate = 1; } } function handleKeyDown(event) { if (event.key === 'ArrowRight') { longPressTimer = setTimeout(() => { isLongPress = true; enable2xPlayback(); }, 1000); // Adjust the duration for long press as needed (in milliseconds) } } function handleKeyUp(event) { if (event.key === 'ArrowRight') { clearTimeout(longPressTimer); isLongPress = false; } } function init() { video = document.querySelector('video'); if (!video) { console.error('Video element not found'); return; } document.addEventListener('keydown', handleKeyDown); document.addEventListener('keyup', handleKeyUp); video.addEventListener('keydown', (event) => { if (event.key === 'ArrowRight') { event.preventDefault(); } }); } window.addEventListener('DOMContentLoaded', init); })();