Prevent Spacebar from Scrolling in YouTube

I want youtube to scroll down when I hit the space bar.

said no one, ever

If the default spacebar behavior when trying to watch videos irks you like it bothers me, then you can use this simple Chrome user script to get the desired functionality. With this script, the space bar will cause the current YouTube video to pause and unpause instead of having it scroll out of view.

For instructions on how to install a chrome user script, see Preventing Drag and Drop Disasters with a Chrome UserScript, and as always, make sure you understand the code before installing it, since a malicious user script can access page contents as well as what you type.

// ==UserScript==
// @match https://**
// ==/UserScript==

document.body.addEventListener("keydown", function(e) {
    if (e.keyCode == 32) {
        var player = document.getElementsByTagName("video")[0]
        if (player.paused) {
        } else {
        return false;

As always, let me know of any improvements or suggestions in the comments.