Skip to content

Instantly share code, notes, and snippets.

@satyr
Created May 14, 2010 22:07
Show Gist options
  • Save satyr/401738 to your computer and use it in GitHub Desktop.
Save satyr/401738 to your computer and use it in GitHub Desktop.
emblur
// ==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