Skip to content

Instantly share code, notes, and snippets.

@Minion3665
Last active March 21, 2025 18:06
Show Gist options
  • Save Minion3665/0344f4716cf3b34c445e7f9ff1b87ba9 to your computer and use it in GitHub Desktop.
Save Minion3665/0344f4716cf3b34c445e7f9ff1b87ba9 to your computer and use it in GitHub Desktop.
Leave my keybinds alone userscript
// ==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