Last active
March 31, 2016 12:34
-
-
Save WillMoggridge/9e5447226deff138439124186246b347 to your computer and use it in GitHub Desktop.
Prevent websites stealing keyboard shortcuts I use all the time... Modified from https://gist.github.com/rodneyrehm/5213304.
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 anti key-grabber | |
// @description Prevent web apps from capturing and muting vital keyboard shortcuts | |
// @grant none | |
// @version 1.2 | |
// ==/UserScript== | |
(function(){ | |
var isMac = unsafeWindow.navigator.oscpu.toLowerCase().contains("mac os x"); | |
unsafeWindow.document.addEventListener('keydown', function(e) { | |
// // No modifiers. Block any usage. | |
// switch (e.keycode) { | |
// case 116: // F5 | |
// e.stopImmediatePropagation(); | |
// return; | |
// } | |
// Block keys with modifiers. Cmd for OSX, Ctrl for Linux/Windows. | |
var modifier = isMac ? e.metaKey : e.ctrlKey; | |
if (!modifier) { | |
return; | |
} | |
switch (e.keyCode) { | |
case 75: // K - search | |
case 76: // L - focus awesome bar | |
case 82: // R - reload tab | |
case 84: // T - open tab | |
case 87: // W - close window | |
e.stopImmediatePropagation(); | |
return; | |
} | |
if (isMac) { | |
switch (e.keyCode) { | |
case 188: // , (comma) - open settings [mac] | |
e.stopImmediatePropagation(); | |
return; | |
} | |
} | |
}, true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment