Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasumiru/c2b08969b22bd74f4b43de12c0247831 to your computer and use it in GitHub Desktop.
Save kasumiru/c2b08969b22bd74f4b43de12c0247831 to your computer and use it in GitHub Desktop.
Disable YouTube Spacebar Scrolling
// ==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);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment