Created
January 10, 2021 16:33
-
-
Save bliaxiong/94541bc1f5fff361bf5e7da94deaf6d3 to your computer and use it in GitHub Desktop.
Youtube userscript to block ads in videos
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
const observer = new MutationObserver(mutations => { | |
for(const mutation of mutations) { | |
for(const addedNode of mutation.addedNodes) { | |
if(addedNode.tagName === "VIDEO") { | |
const video = addedNode | |
video.addEventListener("timeupdate", () => { | |
const adSkipButton = document.querySelector(".ytp-ad-skip-button-slot button,.ytp-ad-overlay-close-button") | |
if(adSkipButton) { | |
adSkipButton.click() | |
} | |
if(document.querySelector(".ad-showing")) { | |
video.currentTime = video.duration | |
} | |
}) | |
} | |
} | |
} | |
}) | |
observer.observe(document.documentElement, { subtree: true, childList: true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment