Disable YouTube Spacebar Scrolling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Disable YouTube spacebar scrolling | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Disables spacebar scrolling and forces it to pause the video instead | |
// @author HPZ07 | |
// @match https://www.youtube.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.addEventListener('keydown', function(e) { | |
if (e.keyCode === 32 && e.target === document.body && isWatchPage()) { | |
e.preventDefault(); | |
var video = document.querySelector('video.html5-main-video'); | |
if (video.currentTime > 0 && !video.paused && !video.ended) { | |
video.play(); | |
} else { | |
video.pause(); | |
} | |
} | |
}); | |
function isWatchPage() { | |
return /^\/watch/.test(location.pathname); | |
} | |
})(); |
Thanks!
Thank you it works!
maybe it should get disabled in the frontpage/channel pages since there's no video to pause there
Thank you it works! maybe it should get disabled in the frontpage/channel pages since there's no video to pause there
It's great to know that it's working! Thanks for the suggestion.
for youtube shorts
https://gist.github.com/HPZ07/6ceae50e64fd280f6031366858a29aa4
looks like the bug got fixed (for me)
and having the userscript enabled makes pressing the spacebar pauses and continues the video quickly
maybe you should comment the whole thing? or make a small notification to tell the users to disable the userscript?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this script, you need to have Tampermonkey or a similar user script manager installed in your browser. Once installed, simply copy and paste the code into a new user script and save it. The script should automatically run on YouTube pages and disable the spacebar scrolling behavior.
Note that this script may not work if YouTube changes its code in the future. If that happens, you may need to update the script accordingly..