published on in web tech

Selectively block webpages from hijacking shortcuts on a webpage

Do you like the new Brave/Chrome tab finder ctrl+shift+a but it’s conflicting with slacks shortcut for Open the All unreads view?

If you use StopTheMadness (https://micro.blog/lapcatsoftware@appdot.net) then you can stop a webpage from hijacking any CMD shortcut (or any shortcut), but what if you want to allow the webpage to keep most shortcuts, but disable one? Add the following code to the custom-script part of StopTheMadness for the slack domain

window.addEventListener('keydown', function(e) {
    if (e.metaKey && e.shiftKey && e.code === 'KeyA') {
        e.stopImmediatePropagation();
    }
}, true);

This can of course be modified to fit your favourite application and browser shortcut.