您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Force spacebar to play/pause videos
当前为
// ==UserScript== // @name Youtube Spacebar Fix // @namespace YouTube Spacebar Fix // @description Force spacebar to play/pause videos // @version 2.3 // @author DryChicken // @match http://*.youtube.com/* // @match https://*.youtube.com/* // @exclude https://*.youtube.com/embed/* // @exclude https://music.youtube.com/* // @grant none // @license MIT // ==/UserScript== // Function to determine if on a YouTube Short function isYouTubeShort() { const currentUrl = window.location.href; return currentUrl.includes('shorts') } function getKeyboardEvent(key, type) { return new KeyboardEvent(type, { key: key, keyCode: key.toUpperCase().charCodeAt(0), bubbles: true, cancelable: true, }); } function simulateKeyDown(key) { let keydownEvent = getKeyboardEvent(key, 'keydown'); document.dispatchEvent(keydownEvent); } function simulateKeyUp(key) { let keyupEvent = getKeyboardEvent(key, 'keyup'); document.dispatchEvent(keyupEvent); } // Function to simulate the pressing and releasing of a key function simulateKeyPress(key) { simulateKeyDown(key); simulateKeyUp(key); } function shortsPlayPause() { const shortsPlayer = document.querySelector('#shorts-player'); if (shortsPlayer) shortsPlayer.click(); } // Keyup on spacebar - when it works, is YouTube's default play/pause video document.addEventListener("keyup", function(event) { if (event.key !== " ") return; // If in search bar or comment input let ae = document.activeElement; if (ae.tagName.toLowerCase() == "input" || ae.hasAttribute("contenteditable")) return; // if (isYouTubeShort()) return; event.preventDefault(); event.stopImmediatePropagation(); }, true); // Use keydown on spacebar to trigger our simulated play/pause action document.addEventListener('keydown', function(event) { if (event.key !== " ") return; // If in search bar or comment input let ae = document.activeElement; if (ae.tagName.toLowerCase() == "input" || ae.hasAttribute("contenteditable")) return; event.preventDefault(); // event.stopImmediatePropagation(); simulateKeyDown('k'); }, true);
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址