Last active
March 21, 2025 18:06
-
-
Save Minion3665/0344f4716cf3b34c445e7f9ff1b87ba9 to your computer and use it in GitHub Desktop.
Leave my keybinds alone userscript
This file contains hidden or 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 Leave my keybinds alone | |
// @namespace Violentmonkey Scripts | |
// @match http*://*/* | |
// @grant none | |
// @version 1.0 | |
// @author Skyler Grey <[email protected]> | |
// @description 19/03/2025 18:14:32: stop websites from overriding common browser keybinds | |
// @license MIT OR Unlicense OR CC0-1.0 | |
// ==/UserScript== | |
const criticalShortcuts = [ | |
{ ctrl: true, key: 'r' }, | |
]; | |
function stopPropagationOfCriticalShortcuts(event) { | |
for (const shortcut of criticalShortcuts) { | |
if ( | |
event.ctrlKey === shortcut.ctrl | |
&& event.key === shortcut.key | |
&& !event.defaultPrevented // we're not too late... | |
&& event.cancelable // this is a threat... | |
) { | |
event.stopImmediatePropagation(); | |
return; | |
} | |
} | |
} | |
document.body.addEventListener('keydown', stopPropagationOfCriticalShortcuts, { capture: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment