Disable website keyboard hooks

Stop websites from hijacking keyboard shortcuts.

Stan na 26-03-2017. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name           Disable website keyboard hooks
// @description    Stop websites from hijacking keyboard shortcuts.
// @author         Isaac Levy, Jonas Singe
// @run-at         document-start
// @include        *
// @grant          none
// @version        0.0.2
// @namespace      https://github.com/isaacl/keycodeScript
// ==/UserScript==

// Disable these keys when no keyboard modifier is pressed
var std_keycodes = new Set([
    // Add keycodes as desired
    37, 38, 39, 40 // Arrow Keys.
]);

// Disable these keys when Meta key is pressed.
var meta_keycodes = new Set([
    // Add keycodes as desired
    70 // Ctrl + F
]);

// Disable these keys when Alt key is pressed.
var alt_keycodes = new Set([
    // Add keycodes as desired
    83 // Alt + S
]);


// Don't change below this line.

var isMac = navigator.platform.indexOf('Mac') >= 0;


document.addEventListener('keydown', function(e) {
    var keycode_set;
    if (isMac ? e.metaKey : e.ctrlKey) {
        keycode_set = meta_keycodes;
    } else if (e.altKey) {
        keycode_set = alt_keycodes;
    } else {
        keycode_set = std_keycodes;
    }

    if (keycode_set.has(e.keyCode)) {
        e.stopImmediatePropagation();
    }
    return false;
});