TheRealJoelmatic / RemoveAdblockThing

The intrusive "Ad blocker are not allowed on YouTube" message is annoying. This open-source project aims to address this issue by providing a solution to bypass YouTube's ad blocker detection
http://joelmatic.com/
MIT License
5.91k stars 318 forks source link

Simple script to skip video ads #602

Closed Sp0kzz closed 2 weeks ago

Sp0kzz commented 3 weeks ago

i've made a simple script to skip all video ads since none of the adblockers/userscripts are working these days: Make sure that no other Ad skipping scripts are running simultaneously and that YouTube is whitelisted in your ad blocker.

// ==UserScript==
// @name         Skip Youtube Ads
// @namespace    http://tampermonkey.net/
// @version      2024-06-15
// @description  Skip Youtube Ads Manually
// @author       You
// @match        https://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    let ii=false;
const observer = new MutationObserver((mutations) => {
    var btn = document.querySelector('.ytp-skip-ad-button');
    if(btn) btn.click();
     var btn2 = document.querySelector('.ytp-preview-ad__text');
    var btn3 = document.querySelector('.ytp-ad-textt');
    if((btn2 || btn3) && !ii){
        let video=document.querySelector('video');
       if(video) video.currentTime = 50;
        ii=true;
        setTimeout(function() {
  ii=false;
}, 100);
    }
});
observer.observe(document.body, { childList: true, subtree: true });
  removePageAds();
     function removePageAds(){
        const style = document.createElement('style');
        style.textContent = `
            ytd-action-companion-ad-renderer,
            ytd-display-ad-renderer,
            ytd-video-masthead-ad-advertiser-info-renderer,
            ytd-video-masthead-ad-primary-video-renderer,
            ytd-in-feed-ad-layout-renderer,
            ytd-ad-slot-renderer,
            yt-about-this-ad-renderer,
            yt-mealbar-promo-renderer,
            ytd-statement-banner-renderer,
            ytd-ad-slot-renderer,
            ytd-in-feed-ad-layout-renderer,
            ytd-banner-promo-renderer-background
            statement-banner-style-type-compact,
            .ytd-video-masthead-ad-v3-renderer,
            div#root.style-scope.ytd-display-ad-renderer.yt-simple-endpoint,
            div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer,
            div#main-container.style-scope.ytd-promoted-video-renderer,
            div#player-ads.style-scope.ytd-watch-flexy,
            ad-slot-renderer,
            ytm-promoted-sparkles-web-renderer,
            masthead-ad,
            tp-yt-iron-overlay-backdrop,

            #masthead-ad {
                display: none !important;
            }
        `;

        document.head.appendChild(style);
    }
})();
CaptainAlex787 commented 3 weeks ago

Thank you so much, it works perfectly. I am even able to watch age restricted videos again and the replay meter on top of the bar is also there again

UkrainianTym commented 3 weeks ago

Sometimes less is more. This works without any issues so far.

Ninjatintin commented 3 weeks ago

hide it from youtube before it's too late

jakeuwu commented 3 weeks ago

How is this so gooooooooood

Yontastic commented 3 weeks ago

does it work with youtube music?

Sp0kzz commented 3 weeks ago

thank you so much for the feedback guys, i have fixed a bug where the videoAd gets stuck :


// ==UserScript==
// @name         Skip Youtube Ads
// @namespace    http://tampermonkey.net/
// @version      2024-06-15
// @description  Skip Youtube Ads Manually
// @author       You
// @match        https://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    let ii=false;
const observer = new MutationObserver((mutations) => {
    var btn = document.querySelector('.ytp-skip-ad-button');
    if(btn) btn.click();
     var btn2 = document.querySelector('.ytp-preview-ad__text');
    var btn3 = document.querySelector('.ytp-ad-textt');
    if((btn2 || btn3) && !ii){
        let video=document.querySelector('video');
       if(video) video.currentTime = 50;
        ii=true;
        setTimeout(function() {
  ii=false;
}, 100);
    }
});
observer.observe(document.body, { childList: true, subtree: true });
  removePageAds();
     function removePageAds(){
        const style = document.createElement('style');
        style.textContent = `
            ytd-action-companion-ad-renderer,
            ytd-display-ad-renderer,
            ytd-video-masthead-ad-advertiser-info-renderer,
            ytd-video-masthead-ad-primary-video-renderer,
            ytd-in-feed-ad-layout-renderer,
            ytd-ad-slot-renderer,
            yt-about-this-ad-renderer,
            yt-mealbar-promo-renderer,
            ytd-statement-banner-renderer,
            ytd-ad-slot-renderer,
            ytd-in-feed-ad-layout-renderer,
            ytd-banner-promo-renderer-background
            statement-banner-style-type-compact,
            .ytd-video-masthead-ad-v3-renderer,
            div#root.style-scope.ytd-display-ad-renderer.yt-simple-endpoint,
            div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer,
            div#main-container.style-scope.ytd-promoted-video-renderer,
            div#player-ads.style-scope.ytd-watch-flexy,
            ad-slot-renderer,
            ytm-promoted-sparkles-web-renderer,
            masthead-ad,
            tp-yt-iron-overlay-backdrop,

            #masthead-ad {
                display: none !important;
            }
        `;

        document.head.appendChild(style);
    }
})();
Radzio-cmd commented 3 weeks ago

Thank u so much, works on opera gx

itzzVarun commented 2 weeks ago

If possible make a repository of this so in future direct updating of the script can be done

survivalizeed commented 2 weeks ago

I agree with itzzVarun. You should make it an own repository instead of posting this in the issues tab. Don't know why the Remove Adblock Thing repository turned into a not working piece of shit. Thanks for the well working script :)

Sp0kzz commented 2 weeks ago

I agree with itzzVarun. You should make it an own repository instead of posting this in the issues tab. Don't know why the Remove Adblock Thing repository turned into a not working piece of shit. Thanks for the well working script :)

I was hoping the Remove Adblock Thing author can maybe implement it in the next update but yes i should make a rep.

oscarr-reyes commented 2 weeks ago

This does not work in firefox

ChristianHinko commented 2 weeks ago

This does not work in firefox

Weird. It's working for me rn.

This is how I used it

annontins commented 2 weeks ago

This does not work in firefox

Weird. It's working for me rn.

This is how I used it

* Open the page to the video

* Perform the following before actually playing the video (not sure if that's important)

* Open the console with F12

* Paste the code

* Type "allow pasting"

* Hit enter

* Play the video

* Enjoy :D

Hey, I'm kinda new to all this stuff. Where do I go about pasting this code?

survivalizeed commented 2 weeks ago

Hey, I'm kinda new to all this stuff. Where do I go about pasting this code?

Just use tampermonkey and paste the code in there

Sp0kzz commented 2 weeks ago

This does not work in firefox

try this improved way of skipping (also for everyone else), the older version had some issues like Remove Adblock 3.8 but this one i've been using it a lot and it always skips the ads:


// ==UserScript==
// @name         Skip Youtube Ads
// @namespace    http://tampermonkey.net/
// @version      2024-06-15
// @description  Skip Youtube Ads Manually
// @author       You
// @match        https://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    let ii=false;
const observer = new MutationObserver((mutations) => {
    var btn = document.querySelector('.ytp-skip-ad-button');
    if(btn) btn.click();
     var btn2 = document.querySelector('.ytp-preview-ad__text');
    var btn3 = document.querySelector('.ytp-ad-textt');
    if((btn2 || btn3) && !ii){
        let video=document.querySelector('video');
       if(video) video.currentTime = 50;
        ii=true;
        setTimeout(function() {
  ii=false;
}, 100);
    }
});
observer.observe(document.body, { childList: true, subtree: true });
  removePageAds();
     function removePageAds(){
        const style = document.createElement('style');
        style.textContent = `
            ytd-action-companion-ad-renderer,
            ytd-display-ad-renderer,
            ytd-video-masthead-ad-advertiser-info-renderer,
            ytd-video-masthead-ad-primary-video-renderer,
            ytd-in-feed-ad-layout-renderer,
            ytd-ad-slot-renderer,
            yt-about-this-ad-renderer,
            yt-mealbar-promo-renderer,
            ytd-statement-banner-renderer,
            ytd-ad-slot-renderer,
            ytd-in-feed-ad-layout-renderer,
            ytd-banner-promo-renderer-background
            statement-banner-style-type-compact,
            .ytd-video-masthead-ad-v3-renderer,
            div#root.style-scope.ytd-display-ad-renderer.yt-simple-endpoint,
            div#sparkles-container.style-scope.ytd-promoted-sparkles-web-renderer,
            div#main-container.style-scope.ytd-promoted-video-renderer,
            div#player-ads.style-scope.ytd-watch-flexy,
            ad-slot-renderer,
            ytm-promoted-sparkles-web-renderer,
            masthead-ad,
            tp-yt-iron-overlay-backdrop,

            #masthead-ad {
                display: none !important;
            }
        `;

        document.head.appendChild(style);
    }
})();
fafarazi commented 2 weeks ago

Thank you so much, it works perfectly 🔥❤