Discussões » Criação de Solicitações
Can I prevent stupid websites(gmail, wikia), from stealing or swallowing browser hotkeys?
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);
});
Thank you very much!
It works great!
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);
});
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)