Skip to content

Instantly share code, notes, and snippets.

@samsondav
Forked from rodneyrehm/anti-keygrabber.user.js
Last active August 29, 2015 14:14
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 samsondav/e1807952d4fd36b91bfd to your computer and use it in GitHub Desktop.
Save samsondav/e1807952d4fd36b91bfd to your computer and use it in GitHub Desktop.
DISABLE binding of some key combinations to web apps, especially Gmail's cmd-enter to send 'feature'
// ==UserScript==
// @name anti key-grabber
// @description Prevent web apps from capturing and muting vital keyboard shortcuts
// @grant none
// @version 1.1
// ==/UserScript==
(function(){
var isMac = unsafeWindow.navigator.oscpu.toLowerCase().contains("mac os x");
unsafeWindow.document.addEventListener('keydown', function(e) {
if (e.keyCode === 116) {
// F5 should never be captured
e.stopImmediatePropagation();
return;
}
// Mac uses the Command key, identified as metaKey
// Windows and Linux use the Control key, identified as ctrlKey
var modifier = isMac ? e.metaKey : e.ctrlKey;
// abort if the proper command/control modifier isn't pressed
if (!modifier) {
return;
}
switch (e.keyCode) {
case 87: // W - close window
case 84: // T - open tab
case 76: // L - focus awesome bar
case 74: // J - open downloads panel
case 13: // Enter - (disable cmd-enter to send in gmail)
e.stopImmediatePropagation();
return;
}
// s'more mac love
if (!isMac) {
return;
}
switch (e.keyCode) {
case 188: // , (comma) - open settings [mac]
case 82: // R - reload tab
e.stopImmediatePropagation();
return;
}
}, true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment