Discussions » Creation Requests

Can I prevent stupid websites(gmail, wikia), from stealing or swallowing browser hotkeys?

§
Posted: 21.05.2017.

Can I prevent stupid websites(gmail, wikia), from stealing or swallowing browser hotkeys?

Hi!

Often I ran into websites which steal hotkeys from the browser. Simple keys I would normally use as a browser shortcut such as ".", "-", "/".
Examples: When I have hotkeys disabled in gmail, it swallows them instead and does nothing. On wikia I often try to use / or . to do a quicksearch but they're stole by the website. "/" is particulary often stolen by websites.

Is there a way to prevent this? Preferably for al websites. (Though I guess exceptions might be needed sometimes)

woxxomMod
§
Posted: 22.05.2017.
Edited: 22.05.2017.

Something like this:

// ==UserScript==
// @name        Disable site hotkeys
// @match       https://github.com/*
// @match       https://mail.google.com/*
// @run-at      document-start
// ==/UserScript==

const keys = [
  '/',
  '?',
  '.',
  '-',
];
// full list: https://developer.mozilla.org/docs/Web/API/KeyboardEvent/key/Key_Values

const stopPropagation = e => {
  if (keys.includes(e.key)) {
    e.stopImmediatePropagation();
    e.stopPropagation();
  }
};

['keydown', 'keyup', 'keypress'].forEach(eventName => {
  document.addEventListener(eventName, stopPropagation);
});
§
Posted: 22.05.2017.

Thank you very much!

It works great!

§
Posted: 25.05.2017.

I modded it somewhat for all websites. Still works fine.
I guess I'll need to add "// @exclude"-s if want to use gaming sites.


    // ==UserScript==
    // @name        Disable site hotkeys
	// @include			http*
    // ==/UserScript==
    const keys = [
      '/',
      '?',
      '.',
      '-',
      ',',
    ];
    // full list: https://developer.mozilla.org/docs/Web/API/KeyboardEvent/key/Key_Values
    const stopPropagation = e => {
      if (keys.includes(e.key)) {
        e.stopImmediatePropagation();
        e.stopPropagation();
      }
    };
    ['keydown', 'keyup', 'keypress'].forEach(eventName => {
      document.addEventListener(eventName, stopPropagation);
    });

Post reply

Sign in to post a reply.