Last active
October 2, 2023 05:03
-
-
Save laocoi/b4d7cfbc43c86f6755e59bf922e63442 to your computer and use it in GitHub Desktop.
Remove empty Google Adsense Ads if it is unfilled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ads = document.querySelectorAll('ins'); | |
ads.forEach(ad => { | |
const observer = new MutationObserver( mutations => | |
{ | |
// console.log(mutations); | |
mutations.forEach( record => | |
{ | |
if(record.type === 'attributes') | |
{ | |
const attrname = record.attributeName; | |
const attrvalue = record.target.getAttribute(attrname); | |
// console.log("attribute-name = ", attrname); | |
// console.log("attribute-value = ", attrvalue); | |
if(attrname === 'data-ad-status' && attrvalue === 'unfilled'){ | |
$(ad).closest('.grid__item').remove() | |
} | |
} | |
}); | |
}); | |
observer.observe(ad, { | |
attributes: true, | |
attributeFilter: ['data-ad-status'] | |
}); | |
}) | |
#Modified from source https://elomymelo.com/mutation-observer-to-customize-ads.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment