DEV Community

wimdenherder
wimdenherder

Posted on

Youtube adblocker does not work? Solve it with 6 lines of code (December 2023)

I used to have a chrome extension Adblock to block YouTube video's but somwhere november 2023 it stopped working. YouTube noticed its activity and blocked the full experience whatsoever.

So I tried to code it myself and it turned out to be just 6 lines of code that does the trick:

setInterval(async () => {
    if(!document.querySelector('.ad-showing')) return;
    document.querySelector('video').currentTime = 1000;
    await (async () => new Promise(r => setTimeout(r, 100)))();
    document.querySelector('.ytp-ad-skip-button-slot')?.click();
}, 300);
Enter fullscreen mode Exit fullscreen mode

This is what it does

  • checks if an ad is displayed
  • skips advertisement to 1000 seconds
  • waits 0,1 sec
  • clicks skip button

Around this you will find the setInterval that executes the function every 0,3 sec

Create a Chrome Extension

This is the ChatGPT prompt:

Create a chrome extension that executes the following script on a youtube page. No pop up. No background script. Manifest version 3.
setInterval(async () => {
if(!document.querySelector('.ad-showing')) return;
document.querySelector('video').currentTime = 1000;
await (async () => new Promise(r => setTimeout(r, 100)))();"

Click this link to find ChatGPT's instruction how to create and install the Chrome Extension. It's really simple!

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay