Skip to content

Instantly share code, notes, and snippets.

@EMG999
Last active July 7, 2025 21:51
Show Gist options
  • Save EMG999/4fd4564b75f1e54697e3755171a3e05b to your computer and use it in GitHub Desktop.
Save EMG999/4fd4564b75f1e54697e3755171a3e05b to your computer and use it in GitHub Desktop.
javascript:const clear=(()=>{let e=e=>null!=e,r=["ytd-video-masthead-ad-v3-renderer","ytd-engagement-panel-title-header-renderer","ytd-display-ad-renderer","ytd-promoted-sparkles-web-renderer","ytd-compact-promoted-video-renderer","ytd-action-companion-ad-renderer","ytd-action-engagement-panel-content-renderer","ytd-banner-promo-renderer","ytd-in-feed-ad-layout-renderer","ytd-ad-inline-playback-meta-block","ytd-player-legacy-desktop-watch-ads-renderer","ytd-ads-engagement-panel-content-renderer"],o=setInterval(()=>{for(staticAd in r)e(document.querySelector(r[staticAd]))&&(document.querySelector(r[staticAd]).remove(),console.info("%cStatic Ad Blocked!","background: rgba(0,204,0,0.2); color: yellow;display: block"));let o=document.querySelectorAll(".ad-showing")[0],l=document.getElementsByClassName("ytp-ad-skip-button")[0];if(e(o)){let t=document.querySelector("video");e(t)&&(t.currentTime=t.duration,l.click(),console.info("%cAd Blocked!","background: rgba(0,204,0,0.2); color: yellow;display: block"))}},1);return function(){clearTimeout(o)}})();
const clear = (() => {
const defined = v => v !== null && v !== undefined;
const staticAds = ["ytd-video-masthead-ad-v3-renderer","ytd-engagement-panel-title-header-renderer","ytd-display-ad-renderer","ytd-promoted-sparkles-web-renderer","ytd-compact-promoted-video-renderer","ytd-action-companion-ad-renderer","ytd-action-engagement-panel-content-renderer","ytd-banner-promo-renderer","ytd-in-feed-ad-layout-renderer","ytd-ad-inline-playback-meta-block","ytd-player-legacy-desktop-watch-ads-renderer","ytd-ads-engagement-panel-content-renderer"];
const timeout = setInterval(() => {
for(staticAd in staticAds){
if(defined(document.querySelector(staticAds[staticAd]))){
document.querySelector(staticAds[staticAd]).remove();
console.info("%cStatic Ad Blocked!",'background: rgba(0,204,0,0.2); color: yellow;display: block');
}
}
const ad = document.querySelectorAll('.ad-showing')[0];
const $skip = document.getElementsByClassName("ytp-ad-skip-button")[0]
if (defined(ad)) {
const video = document.querySelector('video');
if (defined(video)) {
video.currentTime = video.duration;
$skip.click();
console.info("%cAd Blocked!",'background: rgba(0,204,0,0.2); color: yellow;display: block');
}
}
},
1);
return function() {
clearTimeout(timeout);
}
})();
@EMG999
Copy link
Author

EMG999 commented May 3, 2023

Once "installed", this bookmarklet can be used to immediately skip any YouTube ads. Once enabled in a tab, it will continue to run in that tab until the page is reloaded or the tab is closed.

To use do as follows depending on your browser:
Brave/Chrome/Chromium

  1. bookmark this page (drag the lock icon from the omnibar to your bookmark bar)
  2. triple-click the code on this page to select it all and then copy it to your clipboard
  3. right-click on the new bookmark and select "Edit..."
  4. edit the "Name" bookmark to "YouTube Ad Skipper"
  5. delete the current "URL" and replace it with the above code by pasting your clipboard contents

Firefox

  1. bookmark this page (drag the lock icon from the omnibar to your bookmark bar)
  2. triple-click the code on this page to select it all and then copy it to your clipboard
  3. right-click on the new bookmark and select "Properties"
  4. edit the "Name" to be "YouTube Ad Skipper"
  5. delete the current "Location" and replace it with the above code by pasting your clipboard contents

@bensmithgb53
Copy link

Hi mate really impressed with this but only thing please could you add it so it auto skips the ads insead of me having me to click skip add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment