Skip to content

Commit

Permalink
Merge pull request #39 from MarcellPerger1/fix-w3schools
Browse files Browse the repository at this point in the history
Try to reduce RAM usage for websites with ad iframes
  • Loading branch information
MarcellPerger1 authored Apr 7, 2024
2 parents 296e802 + 68d22ce commit 468ec55
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/debug/adblocker.debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/debug/bookmarklet.debug.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/release/adblocker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/release/bookmarklet.min.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion src/adblocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<!lo|re|he)ad(vertisement)?s?(thrive)?(content)?(engine|ngin)?(container)?s?($|[-_,\s])/.test(name)) {
if(/(?<!lo|re|he)[aA]d(vertisement)?s?([tT]hrive)?([cC]ontent)?([eE]ngine|[nN]gin)?([cC]ontainer)?s?($|[-_,\s])/.test(name)) {
return true;
}
}
Expand All @@ -105,6 +106,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"],
Expand Down

0 comments on commit 468ec55

Please sign in to comment.