DEV Community

Cover image for Make your own YouTube AdBlocker for FREE!
CristoferK
CristoferK

Posted on

Make your own YouTube AdBlocker for FREE!

Hello! Are you tired of watching youtube ads? Why not make your own adblocker for free!
Let's start!

setInterval(function(){

    var skipButton = document.getElementsByClassName("ytp-ad-skip-button");
    if(skipButton != undefined && skipButton.length > 0) {
            console.log("Ad detected");
            skipButton[0].click();
    }

}, 3000)
Enter fullscreen mode Exit fullscreen mode
{

    "manifest_version": 2,
    "name": "Youtube Ad Skiper",
    "description": "This extension will help you to watch your favorite videos, without the intervention of Advertisements!",
    "version": "1.0",
    "author": "CristoferK",
    "icons":{
        "600":"logo.png"
    },

    "browser_action":{
        "default_popup":"popup.html"
    },

    "content_scripts": [{
        "js": ["script.js"],
        "run_at": "document_idle",
        "matches": ["<all_urls>"]
    }],
    "permissions": [
        "tabs",
        "activeTab"
    ]

}
Enter fullscreen mode Exit fullscreen mode

Don't forget to subscribe to my YouTube channel for programming tutorials: https://www.youtube.com/channel/UCFzeA3xC-_i4ZT-XwcwsJxQ

Top comments (3)

Collapse
 
czed13 profile image
Info Comment hidden by post author - thread only accessible via permalink

What a terrible code to share.
Having "matches": [""] means it will run on ALL webpages, not only youtube.* domains.

Not to mention you're not "blocking" the ads but waiting for them to timeout and clicking on the "skip ad" button : skipButton[0].click();

100% Clickbaity title

Collapse
 
thebugcoder profile image
TheBugCoder

Nice!!

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more