diff --git a/dist/debug/adblocker.debug.js b/dist/debug/adblocker.debug.js index 9241a79..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(/(?{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..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(/(?{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..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)||(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..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)||(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 diff --git a/src/adblocker.js b/src/adblocker.js index d46f57e..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(/(? 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"],