Created
May 14, 2010 22:07
-
-
Save satyr/401738 to your computer and use it in GitHub Desktop.
emblur
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 emblur | |
// @desc Unfocuses <embed>/<object> on focus. | |
// @help Hold shift/ctrl to turn off temporarily. | |
// @include main | |
// @author satyr | |
// @license X | |
// ==/UserScript== | |
function emblur(e){ | |
switch(e.type){ | |
case 'keydown': case 'keyup': | |
return emblur.off = e.shiftKey || e.ctrlKey; | |
} | |
if(emblur.off || emblur.ignore.test(e.target.tagName)) return; | |
clearTimeout(emblur.tim); | |
emblur.tim = setTimeout( | |
function _emblur(lm) lm && lm.blur(), 500, e.target); | |
} | |
emblur.ignore = /^(?!embed$|object$)/i; | |
let(c = document.getElementById('content')){ | |
for each(let type in ['focus', 'keydown', 'keyup']) | |
c.addEventListener(type, emblur, type === 'focus'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment