Disable The Space Bar’s Page Down Function On YouTube

The space bar is tied to two different functions in a browser; on a normal web page it will scroll the page down. On YouTube it will play/pause a video on a good day. If you use the space bar to scroll pages and it genuinely makes reading and browsing easier than it would be if you used two-finger scroll or the mouse wheel, you won’t mind that it rarely pauses/plays YouTube videos and instead just scrolls the page down. If, however you find the space bar’s scroll behavior on YouTube annoying you might want to disable it. Here’s how.
The space bar’s page scroll shortcut is implemented at the browser level and not even Firefox has a way to disable it. To do so you need to use a script. In order to run a script you will have to rely on an add-on or extension to run it. This means for browsers that don’t support add-ons or extensions, this trick isn’t going to work.
If your browser does support extensions, add-ons, or the ability to run user scripts you’re good to go. Firefox users can use Greasemonkey and Chrome users can install Tampermonkey (links at the end).
chrome-Tampermonkey
Once you have the tool to run the script all set up, add the following script;
// ==UserScript==
// @name Disable space bar scrolling
// @namespace Disable Space bar scroll
// @version 0.1
// @description disable space bar scroll
// @author Space bar scroll
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==

(function() {
var k = function(action){
var eventObj = document.createEvent("Events");

eventObj.initEvent("keydown", true, true);
eventObj.keyCode = 75;
eventObj.which = 75;

document.body.dispatchEvent(eventObj);
};

var killSpaceBar = function(evt) {

var target = evt.target || {},
isInput = ("INPUT" == target.tagName || "TEXTAREA" == target.tagName || "SELECT" == target.tagName || "EMBED" == target.tagName);

// if we're an input or not a real target exit
if(isInput || !target.tagName) return;

// if we're a fake input like the comments exit
if(target && target.getAttribute && target.getAttribute('role') === 'textbox') return;

// ignore the space and send a 'k' to pause
if (evt.keyCode === 32) {
evt.preventDefault();
k();
}
};

document.addEventListener("keydown", killSpaceBar, false);

})();

You might need to restart the browser in Firefox’s case. Reload YouTube and the script will now prevent the space bar from scrolling the page down.
Thanks for reading my news about Disable The Space Bar’s Page Down Function On YouTube at my blog GETPCGAMESET if you want too share this article, please put the resource, and if you think this article is very usefully dont forget to bookmark this site with CTRL + D on your keyboard to web browser.

New and Hot Article's :