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

This simple code works perpect -- fixed a bug where the videoAd gets stuck : #610

Closed kschoi2 closed 2 weeks ago

kschoi2 commented 2 weeks ago
          thank you so much for the feedback guys, i have fixed a bug where the videoAd gets stuck :

by Sp9kzz


// ==UserScript==
// @name         Skip Youtube Ads
// @namespace    http://tampermonkey.net/
// @version      2024-06-11
// @description  Skip Youtube Ads
// @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');
    if(btn2 && !ii){
        document.querySelector('video').currentTime = document.querySelector('video').duration;
        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);
    }
})();

_Originally posted by @Sp0kzz in https://github.com/TheRealJoelmatic/RemoveAdblockThing/issues/602#issuecomment-2162155285_
muchandr commented 2 weeks ago

This solution does not destroy the YouTube Enhancer UI like 5.6 does

Another alternative I found is 4 lines added to uBlock Origin https://github.com/TheRealJoelmatic/RemoveAdblockThing/issues/609

This option actually also conflicts with YouTube Enhancer, but only sometimes.