Last active
March 16, 2023 01:47
-
-
Save Gkjsdll/940fb04699a56c240772e2677f6942e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Disable Youtube 0-9 Hotkeys | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1.1 | |
// @description Disables Youtube 0-9 hotkeys. | |
// @author Zack (Gkjsdll) Winchell | |
// @icon https://www.youtube.com/s/desktop/b7e72d39/img/favicon_144.png | |
// @match *://www.youtube.com/* | |
// @match *://m.youtube.com/* | |
// @grant none | |
// ==/UserScript== | |
const targetIsInput = (event) => { | |
const { target: { isContentEditable, tagName } } = event; | |
const inputTagNames = ['INPUT', 'SELECT', 'TEXTAREA']; | |
if (inputTagNames.includes(tagName)) { | |
return true; | |
} | |
if (isContentEditable) { | |
return true; | |
} | |
return false; | |
} | |
const kaydownHandler = (event) => { | |
const { key, target: { isContentEditable, tagName } } = event; | |
// Don't prevent entering numbers in input areas | |
if (targetIsInput(event)) { | |
return; | |
} | |
// Trap number keys | |
if (key >= '0' && key <= '9') { | |
event.stopImmediatePropagation(); | |
} | |
} | |
window.addEventListener('keydown', kaydownHandler, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment