Skip to content

Instantly share code, notes, and snippets.

@HPZ07
Created May 7, 2023 20:50
Show Gist options
  • Save HPZ07/6ceae50e64fd280f6031366858a29aa4 to your computer and use it in GitHub Desktop.
Save HPZ07/6ceae50e64fd280f6031366858a29aa4 to your computer and use it in GitHub Desktop.
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);
}
})();
@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