Disable keyboard shortcuts

Stop websites from highjacking keyboard shortcuts

目前為 2019-09-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name           Disable keyboard shortcuts
// @description    Stop websites from highjacking keyboard shortcuts
//
// @run-at         document-start
// @include        *
// @grant          none
// @inject-into    auto
// @version        2019.09.23.0010
// @namespace      https://greasyfork.org/users/30
// ==/UserScript==
/* jshint esversion: 6 */

//https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
const keyValues = new Set(['/','Escape']); // Check on https://keycode.info/

const preventKey = function(e){
    if (keyValues.has(e.key)){
        e.stopImmediatePropagation();
    }
    //console.log('Event: type: %s, key: %s, has: %s', e.type, e.key, keyValues.has(e.key));
};

// Slash search on https://github.com/
document.addEventListener('keydown', preventKey, {passive: false, capture: true});
// Slash search on https://forum.manjaro.org/
// `capture` for Slash search on https://phabricator.services.mozilla.com/
document.addEventListener('keypress', preventKey, {passive: false, capture: true});
// I need to find test case
//document.addEventListener('keyup', preventKey);