Skip to content

Instantly share code, notes, and snippets.

@quienn
Last active November 28, 2022 13:12
Show Gist options
  • Save quienn/5072e037cdc30af1e6c7594af5c4957c to your computer and use it in GitHub Desktop.
Save quienn/5072e037cdc30af1e6c7594af5c4957c to your computer and use it in GitHub Desktop.
Userscript that blocks YouTube ads
if (window.location.hostname === 'www.youtube.com') {
const adBlocker = setInterval(() => {
const ad = [...document.querySelectorAll('.ad-showing')][0];
if (ad) {
document.querySelector('video').playbackRate = 10;
const btn = document.querySelector('.videoAdUiSkipButton,.ytp-ad-skip-button');
if (btn) {
btn.click();
}
} else {
clearInterval(adBlocker);
}
}, 50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment