From a6075a3b5f175e62d36e5820e27ca586c2b4a0a9 Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sun, 7 Apr 2024 14:46:12 +0100 Subject: [PATCH 1/4] Try to reduce RAM usage for websites with ad iframes --- src/adblocker.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/adblocker.js b/src/adblocker.js index d46f57e..51ca179 100644 --- a/src/adblocker.js +++ b/src/adblocker.js @@ -105,6 +105,19 @@ } } }, + { + selector: 'html > iframe', + func(/** @type {HTMLIFrameElement} */elem) { + // Some sanity checks not to accidenally break websites + if(!(elem.sandbox.contains("allow-scripts") && elem.sandbox.contains("allow-same-origin") && elem.sandbox.length == 2)) { + return false; + } + if(!elem.src.toLowerCase().includes("gdpr")) { // Ad iframes very often include a `?gdpr=...` in the URL + return false; + } + return true; + } + }, ], ignore: { selector: ["body", ".ad-layout", "#game-holder.game-holder-with-ad"], From 8baaeccffd84325a68f49823c8c0beb744df592e Mon Sep 17 00:00:00 2001 From: MarcellPerger1 Date: Sun, 7 Apr 2024 13:47:46 +0000 Subject: [PATCH 2/4] Build bookmarklet --- dist/debug/adblocker.debug.js | 2 +- dist/debug/bookmarklet.debug.txt | 2 +- dist/release/adblocker.min.js | 2 +- dist/release/bookmarklet.min.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/debug/adblocker.debug.js b/dist/debug/adblocker.debug.js index 9241a79..6254d57 100644 --- a/dist/debug/adblocker.debug.js +++ b/dist/debug/adblocker.debug.js @@ -1 +1 @@ -(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(?{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file +(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(? iframe",func(elem){if(!(elem.sandbox.contains("allow-scripts")&&elem.sandbox.contains("allow-same-origin")&&elem.sandbox.length==2)){return false}if(!elem.src.toLowerCase().includes("gdpr")){return false}return true}}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[elem=>{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file diff --git a/dist/debug/bookmarklet.debug.txt b/dist/debug/bookmarklet.debug.txt index 3228c5c..902d8cf 100644 --- a/dist/debug/bookmarklet.debug.txt +++ b/dist/debug/bookmarklet.debug.txt @@ -1 +1 @@ -javascript:(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(?{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file +javascript:(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(? iframe",func(elem){if(!(elem.sandbox.contains("allow-scripts")&&elem.sandbox.contains("allow-same-origin")&&elem.sandbox.length==2)){return false}if(!elem.src.toLowerCase().includes("gdpr")){return false}return true}}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[elem=>{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file diff --git a/dist/release/adblocker.min.js b/dist/release/adblocker.min.js index 693618f..8b4a364 100644 --- a/dist/release/adblocker.min.js +++ b/dist/release/adblocker.min.js @@ -1 +1 @@ -(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(r.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let r=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of r)e(t)&&a.elem(t)}},r=new Set,n=new Set;for(let[t,r]of Object.entries(e))if("ignore"!=t)for(let e of r)a[t](e);for(let[e,o]of r)n.has(e)||(n.add(e),o.isConnected&&t(o)&&(o.hasChildNodes()||a.elem(o)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(?{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file +(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(n.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let n=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of n)e(t)&&a.elem(t)}},n=new Set,o=new Set;for(let[t,n]of Object.entries(e))if("ignore"!=t)for(let e of n)a[t](e);for(let[e,r]of n)o.has(e)||(o.add(e),r.isConnected&&t(r)&&(r.hasChildNodes()||a.elem(r)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(? iframe",func:e=>!(!e.sandbox.contains("allow-scripts")||!e.sandbox.contains("allow-same-origin")||2!=e.sandbox.length||!e.src.toLowerCase().includes("gdpr"))}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[e=>{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file diff --git a/dist/release/bookmarklet.min.txt b/dist/release/bookmarklet.min.txt index d5dd988..110b4ff 100644 --- a/dist/release/bookmarklet.min.txt +++ b/dist/release/bookmarklet.min.txt @@ -1 +1 @@ -javascript:(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(r.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let r=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of r)e(t)&&a.elem(t)}},r=new Set,n=new Set;for(let[t,r]of Object.entries(e))if("ignore"!=t)for(let e of r)a[t](e);for(let[e,o]of r)n.has(e)||(n.add(e),o.isConnected&&t(o)&&(o.hasChildNodes()||a.elem(o)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(?{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file +javascript:(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(n.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let n=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of n)e(t)&&a.elem(t)}},n=new Set,o=new Set;for(let[t,n]of Object.entries(e))if("ignore"!=t)for(let e of n)a[t](e);for(let[e,r]of n)o.has(e)||(o.add(e),r.isConnected&&t(r)&&(r.hasChildNodes()||a.elem(r)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(? iframe",func:e=>!(!e.sandbox.contains("allow-scripts")||!e.sandbox.contains("allow-same-origin")||2!=e.sandbox.length||!e.src.toLowerCase().includes("gdpr"))}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[e=>{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file From d0a0a0e03daed1a08fd53f8d4e83c861d8fb40be Mon Sep 17 00:00:00 2001 From: Marcell Perger Date: Sun, 7 Apr 2024 15:11:14 +0100 Subject: [PATCH 3/4] Add some case-insensitivity (for first letters) --- src/adblocker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/adblocker.js b/src/adblocker.js index 51ca179..b603db4 100644 --- a/src/adblocker.js +++ b/src/adblocker.js @@ -85,10 +85,11 @@ func: [ { selector: '[class*="ad"],[id*="ad"]', + /** This is the one that gets most of them, rest is just special cases */ func(elem) { for (const name of [elem.id, ...elem.classList]) { // TODO also check lowercase followed by uppercase at end e.g. adBox - if(/(? Date: Sun, 7 Apr 2024 14:11:38 +0000 Subject: [PATCH 4/4] Build bookmarklet --- dist/debug/adblocker.debug.js | 2 +- dist/debug/bookmarklet.debug.txt | 2 +- dist/release/adblocker.min.js | 2 +- dist/release/bookmarklet.min.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/debug/adblocker.debug.js b/dist/debug/adblocker.debug.js index 6254d57..19d0406 100644 --- a/dist/debug/adblocker.debug.js +++ b/dist/debug/adblocker.debug.js @@ -1 +1 @@ -(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(? iframe",func(elem){if(!(elem.sandbox.contains("allow-scripts")&&elem.sandbox.contains("allow-same-origin")&&elem.sandbox.length==2)){return false}if(!elem.src.toLowerCase().includes("gdpr")){return false}return true}}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[elem=>{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file +(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(? iframe",func(elem){if(!(elem.sandbox.contains("allow-scripts")&&elem.sandbox.contains("allow-same-origin")&&elem.sandbox.length==2)){return false}if(!elem.src.toLowerCase().includes("gdpr")){return false}return true}}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[elem=>{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file diff --git a/dist/debug/bookmarklet.debug.txt b/dist/debug/bookmarklet.debug.txt index 902d8cf..5f95763 100644 --- a/dist/debug/bookmarklet.debug.txt +++ b/dist/debug/bookmarklet.debug.txt @@ -1 +1 @@ -javascript:(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(? iframe",func(elem){if(!(elem.sandbox.contains("allow-scripts")&&elem.sandbox.contains("allow-same-origin")&&elem.sandbox.length==2)){return false}if(!elem.src.toLowerCase().includes("gdpr")){return false}return true}}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[elem=>{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file +javascript:(function(what){function shouldIgnore(elem){for(let s of what.ignore?.selector??[]){if(elem.matches(s)){return true}}for(let f of what.ignore?.func??[]){if(f(elem)){return true}}return false}function isContainerElem(elem){return["DIV","SPAN"].includes(elem.tagName)}var rm={elem(elem){if(!shouldIgnore(elem)){removedElems.add([elem,elem.parentElement]);elem.remove()}},list(elems){Array.from(elems).forEach((v=>rm.elem(v)))},cls(name){rm.list(document.getElementsByClassName(name))},selector(selector){rm.list(document.querySelectorAll(selector))},func({func,selector=null}){let elems=selector==null?document.getElementsByClassName("*"):document.querySelectorAll(selector);for(let elem of elems){if(func(elem)){rm.elem(elem)}}}};var removedElems=new Set;var handledElems=new Set;for(let[name,args]of Object.entries(what)){if(name!="ignore"){for(let arg of args){rm[name](arg)}}}for(let[elem,parent]of removedElems){if(handledElems.has(elem)){continue}handledElems.add(elem);if(!parent.isConnected){continue}if(!isContainerElem(parent)){continue}if(parent.hasChildNodes()){continue}rm.elem(parent)}})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(elem){for(const name of[elem.id,...elem.classList]){if(/(? iframe",func(elem){if(!(elem.sandbox.contains("allow-scripts")&&elem.sandbox.contains("allow-same-origin")&&elem.sandbox.length==2)){return false}if(!elem.src.toLowerCase().includes("gdpr")){return false}return true}}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[elem=>{let articles=document.getElementsByTagName("article");for(let a of articles){if(elem.contains(a)){return true}}}]}}); \ No newline at end of file diff --git a/dist/release/adblocker.min.js b/dist/release/adblocker.min.js index 8b4a364..275d353 100644 --- a/dist/release/adblocker.min.js +++ b/dist/release/adblocker.min.js @@ -1 +1 @@ -(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(n.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let n=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of n)e(t)&&a.elem(t)}},n=new Set,o=new Set;for(let[t,n]of Object.entries(e))if("ignore"!=t)for(let e of n)a[t](e);for(let[e,r]of n)o.has(e)||(o.add(e),r.isConnected&&t(r)&&(r.hasChildNodes()||a.elem(r)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(? iframe",func:e=>!(!e.sandbox.contains("allow-scripts")||!e.sandbox.contains("allow-same-origin")||2!=e.sandbox.length||!e.src.toLowerCase().includes("gdpr"))}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[e=>{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file +(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(n.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let n=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of n)e(t)&&a.elem(t)}},n=new Set,o=new Set;for(let[t,n]of Object.entries(e))if("ignore"!=t)for(let e of n)a[t](e);for(let[e,r]of n)o.has(e)||(o.add(e),r.isConnected&&t(r)&&(r.hasChildNodes()||a.elem(r)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(? iframe",func:e=>!(!e.sandbox.contains("allow-scripts")||!e.sandbox.contains("allow-same-origin")||2!=e.sandbox.length||!e.src.toLowerCase().includes("gdpr"))}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[e=>{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file diff --git a/dist/release/bookmarklet.min.txt b/dist/release/bookmarklet.min.txt index 110b4ff..109c31d 100644 --- a/dist/release/bookmarklet.min.txt +++ b/dist/release/bookmarklet.min.txt @@ -1 +1 @@ -javascript:(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(n.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let n=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of n)e(t)&&a.elem(t)}},n=new Set,o=new Set;for(let[t,n]of Object.entries(e))if("ignore"!=t)for(let e of n)a[t](e);for(let[e,r]of n)o.has(e)||(o.add(e),r.isConnected&&t(r)&&(r.hasChildNodes()||a.elem(r)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(? iframe",func:e=>!(!e.sandbox.contains("allow-scripts")||!e.sandbox.contains("allow-same-origin")||2!=e.sandbox.length||!e.src.toLowerCase().includes("gdpr"))}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[e=>{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file +javascript:(function(e){function t(e){return["DIV","SPAN"].includes(e.tagName)}var a={elem(t){(function(t){for(let a of e.ignore?.selector??[])if(t.matches(a))return!0;for(let a of e.ignore?.func??[])if(a(t))return!0;return!1})(t)||(n.add([t,t.parentElement]),t.remove())},list(e){Array.from(e).forEach((e=>a.elem(e)))},cls(e){a.list(document.getElementsByClassName(e))},selector(e){a.list(document.querySelectorAll(e))},func({func:e,selector:t=null}){let n=null==t?document.getElementsByClassName("*"):document.querySelectorAll(t);for(let t of n)e(t)&&a.elem(t)}},n=new Set,o=new Set;for(let[t,n]of Object.entries(e))if("ignore"!=t)for(let e of n)a[t](e);for(let[e,r]of n)o.has(e)||(o.add(e),r.isConnected&&t(r)&&(r.hasChildNodes()||a.elem(r)))})({cls:["adsbygoogle","mod_ad_container","brn-ads-box","gpt-ad","ad-box","top-ads-container","adthrive-ad"],selector:['[aria-label="advertisement"]','[class*="-ad "],[class*="-ad-"],[class$="-ad"],[class^="ad-"],[class^="adthrive"]',':is(div,iframe)[id^="google_ads_iframe_"]',"#aipPrerollContainer","span[data-ez-ph-id] span[data-ez-ph-owner-id] span.ezoicwhat"],func:[{selector:'[class*="ad"],[id*="ad"]',func(e){for(const t of[e.id,...e.classList])if(/(? iframe",func:e=>!(!e.sandbox.contains("allow-scripts")||!e.sandbox.contains("allow-same-origin")||2!=e.sandbox.length||!e.src.toLowerCase().includes("gdpr"))}],ignore:{selector:["body",".ad-layout","#game-holder.game-holder-with-ad"],func:[e=>{let t=document.getElementsByTagName("article");for(let a of t)if(e.contains(a))return!0}]}}); \ No newline at end of file