Last active
March 22, 2024 18:15
-
-
Save ericc3141/1b03489309e1dbd18cc71dfa5782f3fd to your computer and use it in GitHub Desktop.
Bookmarklet to remove elements from pages.
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:if (typeof(zapper) == "undefined") {window.zapper = {state: 1,over: null,selected: null,select: function(e) {zapper.selected = document.elementFromPoint(e.clientX, e.clientY);zapper.over=document.createElement("div");zapper.over.style="pointer-events:none;position:fixed;z-index:2147483647;background-color:#FF0000;opacity:0.5;";document.body.appendChild(zapper.over);var rect = zapper.selected.getBoundingClientRect();var overS=zapper.over.style;overS.left = rect.left+"px";overS.top = rect.top+"px";overS.width = rect.width+"px";overS.height = rect.height+"px";zapper.state = 2;},zap: function(e) {var selected2 = document.elementFromPoint(e.clientX, e.clientY);if (zapper.selected == selected2){console.log("zapping");selected2.parentElement.removeChild(selected2);}document.body.removeChild(zapper.over);zapper.state=3;console.log("done");}}; document.body.addEventListener("click", function(e){e.preventDefault();console.log("click");if (zapper.state == 1){zapper.select(e);} else if (zapper.state == 2) {zapper.zap(e);}});} else {zapper.state = 1;} |
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
/*States: | |
No run- null | |
ready- 1 | |
selected- 2 | |
done- 3 | |
*/ | |
// Create on first run | |
if (typeof(zapper) == "undefined") { | |
window.zapper = { | |
state: 1, | |
over: null, | |
selected: null, | |
// Show translucent red div over selected element | |
select: function(e) { | |
zapper.selected = document.elementFromPoint(e.clientX, e.clientY); | |
// Create overlay | |
zapper.over=document.createElement("div"); | |
zapper.over.style="pointer-events:none;position:fixed;z-index:2147483647;background-color:#FF0000;opacity:0.5;"; | |
document.body.appendChild(zapper.over); | |
// Set overlay size/location | |
var rect = zapper.selected.getBoundingClientRect(); | |
var overS=zapper.over.style; | |
overS.left = rect.left+"px"; | |
overS.top = rect.top+"px"; | |
overS.width = rect.width+"px"; | |
overS.height = rect.height+"px"; | |
zapper.state = 2; | |
}, | |
// Zap element, remove overlay | |
zap: function(e) { | |
var selected2 = document.elementFromPoint(e.clientX, e.clientY); | |
if (zapper.selected == selected2){ | |
console.log("zapping"); | |
selected2.parentElement.removeChild(selected2); | |
} | |
document.body.removeChild(zapper.over); | |
zapper.state=3; | |
console.log("done"); | |
} | |
}; | |
document.body.addEventListener("click", function(e){ | |
e.preventDefault(); | |
console.log("click"); | |
if (zapper.state == 1){ | |
zapper.select(e); | |
} else if (zapper.state == 2) { | |
zapper.zap(e); | |
} | |
}); | |
} else { | |
// Activated, but not first run. Reset state. | |
zapper.state = 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment