Skip to content

Instantly share code, notes, and snippets.

@HPZ07
Created May 7, 2023 20:50
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Disable YouTube Shorts Spacebar Scrolling
// ==UserScript==
// @name Disable YouTube Shorts spacebar scrolling
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Disables YouTube Shorts scrolling and pauses video on spacebar press
// @author HPZ07
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.addEventListener('keydown', function(e) {
if(!isShortsPage()){
return;
}
if (e.keyCode === 32 && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {
e.preventDefault();
var video = document.querySelector('video.html5-main-video');
if (video !== null && !isNaN(video.duration)) {
if (video.paused) {
video.play();
} else {
video.pause();
}
}
}
});
function isShortsPage() {
return /^\/shorts/.test(location.pathname);
}
})();
@HPZ07
Copy link
Author

HPZ07 commented May 7, 2023

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 Shorts 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.

@waduruwaddi
Copy link

i cant comment at shorts

@davids74
Copy link

Can a script be written which would adjust volume in shorts with up and down arrows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment