Created
April 8, 2015 18:26
-
-
Save pseudosavant/5bed39b9990d3233f77d to your computer and use it in GitHub Desktop.
Bookmarklet to hide DOM elements
This file contains hidden or 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
/* | |
Bookmarklet to hide DOM elements | |
Left-click: hide element | |
Right-click: undo last hide | |
Middle-click: stop altering document | |
JSBin: http://jsbin.com/nimilu/ | |
Convert to a bookmarklet here: http://ted.mielczarek.org/code/mozilla/bookmarklet.html | |
*/ | |
(function(){ | |
var doc = document.querySelector('html'); | |
var originalState = []; | |
function hide(e){ | |
switch (e.button) { | |
case 0: // Left | |
if (e.target !== doc) { // Don't hide the main document | |
originalState.push({el: e.target, display: e.target.style.display}); | |
e.target.style.display = 'none'; | |
} | |
break; | |
case 1: // Middle | |
doc.removeEventListener('mouseup',hide, false); | |
doc.removeEventListener('contextmenu', prevent, false); | |
break; | |
case 2: // Right | |
if (originalState.length > 0) { | |
var state = originalState.pop(); | |
state.el.style.display = state.display; | |
} | |
break; | |
} | |
e.preventDefault(); | |
} | |
function prevent(e){ | |
e.preventDefault(); | |
return false; | |
} | |
doc.addEventListener('mouseup',hide, false); | |
doc.addEventListener('contextmenu', prevent, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment