Leave my keybinds alone

19/03/2025 18:14:32: stop websites from overriding common browser keybinds

// ==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 });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址