Skip to content

Instantly share code, notes, and snippets.

@agibsonsw
Created January 8, 2016 22:10
Show Gist options
  • Save agibsonsw/5bd9f18514683eab70a8 to your computer and use it in GitHub Desktop.
Save agibsonsw/5bd9f18514683eab70a8 to your computer and use it in GitHub Desktop.
Bookmarklet to hide a page element on click
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