Skip to content

Instantly share code, notes, and snippets.

@snydergd
Last active July 8, 2023 20:28
Show Gist options
  • Save snydergd/3463f874e13ec3401d151281f29bddd5 to your computer and use it in GitHub Desktop.
Save snydergd/3463f874e13ec3401d151281f29bddd5 to your computer and use it in GitHub Desktop.
Paywall Remover Script
/*
A quick and dirty javascript to paste in devtools (F12 in browser) console to remove client-side paywalls
After running, you'll have a "hide" button you can press to get rid of the currently displayed paywall/overlay.
You may need to press it several times.
You'll also have a "close" button to hide the buttons.
If you want to use on Android/Chrome, you can! Use the following abbreviated version. Add as a bookmark
(will have to manually re-add the "javascript: " at the front) then launch by typing the name of the bookmark
in the address bar and pressing on it (clicking from the bookmark section does not work). I named my bookmark
"rmp" so that I could find it explicitly faster.
Bookmarklet version made with: https://chriszarate.github.io/bookmarkleter/
javascript:void%20function(){function%20a(a){for((%22wrappedEl%22in%20a.dataset)%26%26(a=widnow.itemLookups[parseInt(a.dataset.wrappedEl)]),console.log(a),a.style.display=%22none%22,window.enforceItemsHidden.push(a);a.parentElement;)a=a.parentElement,%22fixed%22==a.style.position%26%26(a.style.position=%22%22)}function%20b(){for(item%20of%20window.enforceItemsHidden)item.style=%22display:%20none%22;return!1}function%20c(a){return%20a.preventDefault(),a.stopPropagation(),b(),!1}if(window.itemLookups=[],!window.removerButtons){window.removerButtons=document.createElement(%22div%22),window.removerButtons.style.position=%22fixed%22,window.removerButtons.style.top=%220%22,window.removerButtons.style.left=%220%22,window.removerButtons.style.width=%22100%25%22,window.removerButtons.style.zIndex=%226000000001%22,window.removerButtons.style.textAlign=%22center%22,closeButton=document.createElement(%22button%22),closeButton.style.backgroundColor=%22red%22,closeButton.style.padding=%221em%22,closeButton.style.border=%221px%20solid%20black%22,closeButton.style.width=%2249%25%22,closeButton.innerText=%22Close%22,hideButton=document.createElement(%22button%22),hideButton.style.backgroundColor=%22red%22,hideButton.style.padding=%221em%22,hideButton.style.border=%221px%20solid%20black%22,hideButton.style.width=%2249%25%22,hideButton.innerText=%22Hide%22,window.hideClickedElement=function(b){return%22click%22!==b.type%26%26a(this),b.stopPropagation(),!1},goLauncher=function(){return%20window.hideClickedElement.apply(this,arguments)};for(x%20of[...document.querySelectorAll(%22*%22),window]){try{const%20a=getComputedStyle(x);%22none%22==a.pointerEvents%26%26(x.style.pointerEvents=%22auto%22),0%3C=a.filter.indexOf(%22blur%22)%26%26(x.style.filter=%22none%22),%22hidden%22==a.overflowY%26%26(x.style.overflow=%22auto%22)}catch(a){}x.addEventListener(%22scroll%22,c),x.scrollTo=function(){},x.xxyy||(x.addEventListener(%22mousedown%22,goLauncher),x.addEventListener(%22click%22,goLauncher),x.addEventListener(%22touchstart%22,goLauncher),x.xxyy=!0)}for(item%20of%20document.querySelectorAll(%22iframe%22))dummy=document.createElement(%22div%22),dummy.onmousedown=((b,c)=%3Efunction(d){return%20console.log(%22Hello%20there,%20I'm%20being%20removed.%20%20Thank%20you.%22,b,c),a(b),c.remove(),d.stopPropagation(),!1})(item,dummy),dummy.style.zIndex=%226000000001%22,dummy.className=%22delete-me%22,dummy.dataset.wrappedEl=window.itemLookups.length,window.itemLookups.push(item),dummy.style.backgroundColor=%22%23FF000088%22,dummy.style.position=%22absolute%22,dummy.style.left=item.getBoundingClientRect().x+%22px%22,dummy.style.top=item.getBoundingClientRect().y+%22px%22,dummy.style.width=getComputedStyle(item).width,dummy.style.height=getComputedStyle(item).height,console.log(%22HELLO%22,item,dummy),document.body.appendChild(dummy);%22object%22!=typeof%20window.enforceItemsHidden%26%26(window.enforceItemsHidden=[]),closeButton.onmousedown=function(){for(item%20of%20document.querySelectorAll(%22.delete-me%22))item.remove();window.hideClickedElement=function(){},document.body.removeChild(window.removerButtons),window.removerButtons=null},closeButton.ontouchstart=closeButton.onmousedown,hideButton.onmousedown=function(){r=document.body.getBoundingClientRect(),el=document.elementFromPoint(r.width/2,window.innerHeight/2),a(el)},hideButton.ontouchstart=hideButton.onmousedown,window.removerButtons.appendChild(closeButton),window.removerButtons.appendChild(hideButton),document.body.appendChild(window.removerButtons)}}();
*/
window.itemLookups = [];
function goToTown(el) {
if ("wrappedEl" in el.dataset) el = widnow.itemLookups[parseInt(el.dataset.wrappedEl)];
console.log(el);
el.style.display = "none";
window.enforceItemsHidden.push(el);
while (el.parentElement) {
el = el.parentElement;
if (el.style.position == 'fixed') el.style.position = '';
}
}
function doEnforceItemsHidden() {
for (item of window.enforceItemsHidden) {
item.style = "display: none";
}
return false;
}
function stopEvent(e) {
e.preventDefault();
e.stopPropagation();
doEnforceItemsHidden();
return false;
}
if (!window.removerButtons) {
window.removerButtons = document.createElement("div");
window.removerButtons.style.position = "fixed";
window.removerButtons.style.top = "0";
window.removerButtons.style.left = "0";
window.removerButtons.style.width = "100%";
window.removerButtons.style.zIndex = "6000000001";
window.removerButtons.style.textAlign = "center";
closeButton = document.createElement("button");
closeButton.style.backgroundColor = "red";
closeButton.style.padding = "1em";
closeButton.style.border = "1px solid black";
closeButton.style.width = "49%";
closeButton.innerText = "Close";
hideButton = document.createElement("button");
hideButton.style.backgroundColor = "red";
hideButton.style.padding = "1em";
hideButton.style.border = "1px solid black";
hideButton.style.width = "49%";
hideButton.innerText = "Hide";
window.hideClickedElement = function(e) {
if (e.type !== "click") {
goToTown(this);
}
e.stopPropagation();
return false;
};
goLauncher = function(){
return window.hideClickedElement.apply(this, arguments);
};
for (x of [...document.querySelectorAll("*"), window]) {
try {
const c = getComputedStyle(x);
if (c.pointerEvents == "none") x.style.pointerEvents = "auto";
if (c.filter.indexOf("blur") >= 0) x.style.filter = 'none';
if (c.overflowY == "hidden") x.style.overflow = "auto";
} catch (e) {
// probably because of "window"
}
x.addEventListener("scroll", stopEvent);
x.scrollTo = function(){};
if (!x.xxyy) {
x.addEventListener("mousedown", goLauncher);
x.addEventListener("click", goLauncher);
x.addEventListener("touchstart", goLauncher);
x.xxyy = true;
}
}
for (item of document.querySelectorAll("iframe")) {
// Frames require a little TLC
dummy = document.createElement("div");
dummy.onmousedown = ((item, dummy) => function(e) {
console.log("Hello there, I'm being removed. Thank you.", item, dummy);
goToTown(item);
dummy.remove();
e.stopPropagation();
return false;
})(item, dummy);
dummy.style.zIndex = "6000000001";
dummy.className = "delete-me";
dummy.dataset.wrappedEl = window.itemLookups.length;
window.itemLookups.push(item);
dummy.style.backgroundColor = "#FF000088";
dummy.style.position = "absolute";
dummy.style.left = item.getBoundingClientRect().x + 'px';
dummy.style.top = item.getBoundingClientRect().y + 'px';
dummy.style.width = getComputedStyle(item).width;
dummy.style.height = getComputedStyle(item).height;
console.log("HELLO", item, dummy);
document.body.appendChild(dummy);
}
if (typeof(window["enforceItemsHidden"]) !== "object") {
window.enforceItemsHidden = [];
}
closeButton.onmousedown = function(){
for (item of document.querySelectorAll(".delete-me")) {
item.remove();
}
window.hideClickedElement = function(){};
document.body.removeChild(window.removerButtons);
window.removerButtons = null;
};
closeButton.ontouchstart = closeButton.onmousedown;
hideButton.onmousedown = function(){
r = document.body.getBoundingClientRect();
el = document.elementFromPoint(r.width/2, window.innerHeight/2);
goToTown(el);
};
hideButton.ontouchstart = hideButton.onmousedown;
window.removerButtons.appendChild(closeButton);
window.removerButtons.appendChild(hideButton);
document.body.appendChild(window.removerButtons);
}
/*
Pages to test with:
https://scitechdaily.com/palm-sized-powerhouse-rikens-handheld-terahertz-device-to-x-ray-things-without-harmful-radiation/
https://www.nytimes.com/2023/07/08/world/europe/netherlands-refugees-government-collapse.html
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment