Skip to content

Commit

Permalink
Improve neutered adsbygoogle scriptlet
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#786

A case of web page embedding multiple times the
`adsbygoogle.js` script was causing the neutered,
replacement script to create a huge amount of iframes
in the DOM.

The scriptlet has been modified to check if an iframe
tag already exist and skip the creation if so.

Related commits:
- gorhill/uBlock@0934779
- gorhill/uBlock@5fa8739

Co-authored-by: Raymond Hill <rhill@raymondhill.net>
  • Loading branch information
JustOff and gorhill committed Jan 25, 2021
1 parent bba2397 commit b3e6df5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions assets/resources/resources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ googlesyndication.com/adsbygoogle.js application/javascript
window.adsbygoogle = window.adsbygoogle || {
length: 0,
loaded: true,
push: function Si(a) {
push: function Si() {
/*
client = client || google_ad_client || google_ad_client;
slotname = slotname || google_ad_slot;
Expand All @@ -600,16 +600,18 @@ googlesyndication.com/adsbygoogle.js application/javascript
this.length += 1;
}
};
var phs = document.querySelectorAll('.adsbygoogle');
var css = 'height:1px!important;max-height:1px!important;max-width:1px!important;width:1px!important;';
for ( var i = 0; i < phs.length; i++ ) {
var fr = document.createElement('iframe');
fr.id = 'aswift_' + (i+1);
const phs = document.querySelectorAll('.adsbygoogle');
const css = 'height:1px!important;max-height:1px!important;max-width:1px!important;width:1px!important;';
for ( let i = 0; i < phs.length; i++ ) {
const id = `aswift_${(i+1)}`;
if ( document.querySelector(`iframe#${id}`) !== null ) { continue; }
const fr = document.createElement('iframe');
fr.id = id;
fr.style = css;
var cfr = document.createElement('iframe');
cfr.id = 'google_ads_frame' + i;
const cfr = document.createElement('iframe');
cfr.id = `google_ads_frame${i}`;
fr.appendChild(cfr);
document.body.appendChild(fr);
phs[i].appendChild(fr);
}
})();

Expand Down

0 comments on commit b3e6df5

Please sign in to comment.