Skip to content

Instantly share code, notes, and snippets.

@AJamesPhillips
Created July 21, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJamesPhillips/82c4fda8d6c6e13ec2d191407cae9b7c to your computer and use it in GitHub Desktop.
Save AJamesPhillips/82c4fda8d6c6e13ec2d191407cae9b7c to your computer and use it in GitHub Desktop.
Kills some ads
// Based off: https://gist.github.com/jasonleonhard/177b67f135c443719fe8
function removeElement (element) {
element.parentNode.removeChild(element);
}
function removeElements (elements) {
for (var i = 0; i < elements.length; ++i) {
removeElement(elements[i]);
}
}
function killAds() {
console.log("Killing ads")
// remove all iframes
var iframes = document.getElementsByTagName("iframe");
removeElements(iframes);
// remove all scripts
var scripts = document.getElementsByTagName("script");
removeElements(scripts);
// remove other things
const otherClassNames = [".ad-container",".click-layer",".videoAdUi",".ytp-ad-progress","#masthead-positioner","#masthead-positioner-height-offset","#yt-masthead-container",".annotation",".ytp-block-autohide","ad-container"]
otherClassNames.forEach(className => {
const elements = document.getElementsByClassName(className);
removeElements(elements);
})
}
setInterval(killAds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment