您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Disable spacebar scrolling and enable spacebar controls on YouTube
// ==UserScript== // @name YouTube Spacebar Controls // @namespace http://tampermonkey.net/ // @version 0.1 // @description Disable spacebar scrolling and enable spacebar controls on YouTube // @author Temanor // @match *://www.youtube.com/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; function isIgnoredElement(target) { const tagName = target.tagName.toLowerCase(); return tagName === 'input' || tagName === 'textarea' || target.isContentEditable; } function controlVideo(e) { const video = document.querySelector("video"); if (!video || isIgnoredElement(e.target)) return; const player = document.querySelector('.html5-video-player'); const isPlayerInFocus = player && player.contains(document.activeElement); if (isPlayerInFocus) return; if (e.code === 'Space') { e.preventDefault(); if (video.paused) { video.play(); } else { video.pause(); } } } function preventSpaceScroll(e) { if (e.code === 'Space' && e.target === document.body) { e.preventDefault(); } } window.addEventListener('keydown', controlVideo); window.addEventListener('keydown', preventSpaceScroll); })();