Created
July 28, 2014 20:13
-
-
Save jamesgecko/93aaa36a97eb4bcf1a24 to your computer and use it in GitHub Desktop.
Stop Cmd shortcut hijacking in Firefox
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 Disable interceptions of Cmd+t, Cmd+w, Cmd+shift+] and Cmd+shift+[ | |
// @namespace http://userscripts.org/users/642403 | |
// @description Stop websites from hijacking keyboard shortcuts | |
// | |
// @run-at document-start | |
// @include * | |
// @grant none | |
// ==/UserScript== | |
// Keycode for 's' and 't'. Add more to disable other ctrl+X interceptions | |
// http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes | |
shift_keycodes = [219, 221]; // [, ] | |
keycodes = [84, 87]; // t, w | |
(window.opera ? document.body : document).addEventListener('keydown', function(e) { | |
// alert(e.keyCode ); //uncomment to find more keyCodes | |
if (shift_keycodes.indexOf(e.keyCode) != -1 && e.metaKey && e.shiftKey) { | |
e.cancelBubble = true; | |
e.stopImmediatePropagation(); | |
// alert("Gotcha!"); //ucomment to check if it's seeing the combo | |
} | |
if (keycodes.indexOf(e.keyCode) != -1 && e.metaKey) { | |
e.cancelBubble = true; | |
e.stopImmediatePropagation(); | |
// alert("Gotcha!"); //ucomment to check if it's seeing the combo | |
} | |
return false; | |
}, !window.opera); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment