Created
May 26, 2019 01:37
-
-
Save rkuhn/c15b7b913da3eee29241bacac277ab32 to your computer and use it in GitHub Desktop.
GreaseMonkey script to prevent websites from messing with my keyboard shortcuts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name forbid rebinding my keys | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Get off my lawn! | |
// @author Roland Kuhn | |
// @include * | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const SHIFT = 1 | |
const CTRL = 2 | |
const ALT = 4 | |
const META = 8 | |
const p = window.Event.prototype.preventDefault | |
window.Event.prototype.preventDefault = function() { | |
const mod = | |
(this.shiftKey ? SHIFT : 0) | | |
(this.ctrlKey ? CTRL : 0) | | |
(this.altKey ? ALT : 0) | | |
(this.metaKey ? META : 0) | |
if (this.code == 'KeyM' && mod == (SHIFT | META)) { return } | |
if ((this.code == 'ArrowLeft' || this.code == 'ArrowRight') && mod == (ALT | META)) { return } | |
if (this.code == 'KeyF' && mod == (SHIFT | META)) { return } | |
if (this.code == 'KeyR' && mod == META) { return } | |
if (this.code == 'KeyW' && mod == META) { return } | |
if (this.code >= 'Digit0' && this.code <= 'Digit9' && mod == META) { return } | |
if (this.code == 'KeyJ' && mod == (ALT | META)) { return } | |
p.apply(this) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment