Skip to content

Instantly share code, notes, and snippets.

@rkuhn
Created May 26, 2019 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkuhn/c15b7b913da3eee29241bacac277ab32 to your computer and use it in GitHub Desktop.
Save rkuhn/c15b7b913da3eee29241bacac277ab32 to your computer and use it in GitHub Desktop.
GreaseMonkey script to prevent websites from messing with my keyboard shortcuts
// ==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