Skip to content

Instantly share code, notes, and snippets.

@agibsonsw
Created February 5, 2012 16:35
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save agibsonsw/1746472 to your computer and use it in GitHub Desktop.
Save agibsonsw/1746472 to your computer and use it in GitHub Desktop.
JS Bookmarklet to hide an element on click
javascript:(function(){var%20d=document,useMine=true,prevEl;function%20AddHandler(orig,mine)
{return%20function(e){if(useMine)mine(e);else%20if(orig)orig(e);};}function%20Myonmouseover(e)
{var%20evt=e||window.event;var%20elem=evt.target||evt.srcElement;elem.style.outline='2px%20solid%20gray';
prevEl=elem;}function%20Myonmouseout(e){var%20evt=e||window.event;var%20elem=evt.target||evt.srcElement;elem.style.outline='';}
function%20Myonclick(e){var%20evt=e||window.event;var%20elem=evt.target||evt.srcElement;elem.style.display='none';}
function%20Myonkeydown(e){var%20evt=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);})()
@agibsonsw
Copy link
Author

This is a bookmarklet I crafted so that I can click elements, images, on a web page to hide them.

Create a Bookmark and paste the code as the property for the bookmark. Add it as a button on your bookmarks toolbar. If you want to hide something, click the button. As you point around the page a grey box outlines what you will (try) to hide. You can continue clicking, then press Escape to finish.

@RodolpheGohard
Copy link

Awesome ! this is so precious today with all that crap bloating every website out there ...
thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment