Created
January 8, 2016 22:10
-
-
Save agibsonsw/5bd9f18514683eab70a8 to your computer and use it in GitHub Desktop.
Bookmarklet to hide a page element on click
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
javascript: | |
(function(){ | |
var d=document,useMine=true,prevEl; | |
function AddHandler(orig,mine) { | |
return function(e){ | |
if(useMine) | |
mine(e); | |
else | |
if(orig) | |
orig(e); | |
} | |
; | |
} | |
function Myonmouseover(e) { | |
var evt=e||window.event; | |
var elem=evt.target||evt.srcElement; | |
elem.style.outline='2px solid gray'; | |
prevEl=elem; | |
} | |
function Myonmouseout(e){ | |
var evt=e||window.event; | |
var elem=evt.target||evt.srcElement; | |
elem.style.outline=''; | |
} | |
function Myonclick(e){ | |
var evt=e||window.event; | |
var elem=evt.target||evt.srcElement; | |
elem.style.display='none'; | |
} | |
function Myonkeydown(e){ | |
var evt=e||window.event; | |
if(evt.keyCode==27){ | |
prevEl.style.outline=''; | |
useMine=false; | |
} | |
} | |
d.onmouseover=AddHandler(d.onmouseover,Myonmouseover); | |
d.onmouseout=AddHandler(d.onmouseout,Myonmouseout); | |
d.onclick=AddHandler(d.onclick,Myonclick); | |
d.onkeydown=AddHandler(d.onkeydown,Myonkeydown); | |
} | |
)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment