Last active
August 29, 2015 14:03
-
-
Save eevee/1a2107bf31c6ab5872fd to your computer and use it in GitHub Desktop.
userscript that blocks really really annoying js quirks. web devs should really do this crap themselves...
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 key events | |
// @namespace eev.ee | |
// @description Prevents JS on the page from receiving keyup, keydown, or keypress. Fixes, e.g., Twitter's disabling of shortcuts until the page has loaded. | |
// @include https://twitter.com/* | |
// @version 1 | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
"use strict"; | |
var blocker = function(event) { | |
event.stopImmediatePropagation(); | |
}; | |
['keyup', 'keydown', 'keypress'].map(function(event_type) { | |
// Setting useCapture to true ensures the document receives the event | |
// first (during the capture phase, when handlers are run from the | |
// outside in). Most event handlers use bubbling, which runs | |
// inside-out. Even if the page did this same thing, this script runs | |
// before there's any DOM at all, so we're guaranteed (I hope) to be | |
// the first listener, and stopImmediatePropagation will block any | |
// other listeners even for the same event on the same element. | |
document.addEventListener(event_type, blocker, true); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment