Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Youtube ads aren't blocked #1121

Closed
mtgperales opened this issue Jul 10, 2020 · 17 comments
Closed

Youtube ads aren't blocked #1121

mtgperales opened this issue Jul 10, 2020 · 17 comments

Comments

@mtgperales
Copy link

Ads in Youtube suddenly starts popping while the the option "Block all ads and trackers" is enabled. Already checked other websites and the adblocker works on them.

image

image

Using Min v1.15.0

@ca5ua1
Copy link

ca5ua1 commented Jul 23, 2020

HI! I'm using userscript for this. Here it goes:

// ==UserScript==
// @name               No more youtube ads! - UPDATED
// @name:zh-CN         隐藏youtube google广告
// @namespace          FaZe BeeF
// @version            1.0.3
// @description        Automaticly Skips all youtube ads! with no waiting time.
// @description:zh-CN  BF5 : This skips all adds instantly. Youtube.com
// @author             FaZe BeeF
// @match              *://www.youtube.com/*
// ==/UserScript==

(function() {
    'use strict';
    var closeAd=function (){
        var css = '.video-ads .ad-container .adDisplay,#player-ads,.ytp-ad-module,.ytp-ad-image-overlay{ display: none!important; }',
            head = document.head || document.getElementsByTagName('head')[0],
            style = document.createElement('style');

        style.type = 'text/css';
        if (style.styleSheet){
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }

        head.appendChild(style);
    };
    var skipInt;
    var log=function(msg){
       // unsafeWindow.console.log (msg);
    };
    var skipAd=function(){
        //ytp-ad-preview-text
        //ytp-ad-skip-button
        var skipbtn=document.querySelector(".ytp-ad-skip-button.ytp-button")||document.querySelector(".videoAdUiSkipButton ");
        //var skipbtn=document.querySelector(".ytp-ad-skip-button ")||document.querySelector(".videoAdUiSkipButton ");
        if(skipbtn){
           skipbtn=document.querySelector(".ytp-ad-skip-button.ytp-button")||document.querySelector(".videoAdUiSkipButton ");
           log("skip");
           skipbtn.click();
           if(skipInt) {clearTimeout(skipInt);}
           skipInt=setTimeout(skipAd,500);
         }else{
              log("checking...");
              if(skipInt) {clearTimeout(skipInt);}
              skipInt=setTimeout(skipAd,500);
         }
    };

    closeAd();
    skipAd();

})();

@Syndamia
Copy link
Member

@Casul51's solution worked for me, did it work for you @mtgperales?

@mtgperales
Copy link
Author

mtgperales commented Jul 27, 2020

Sorry for the late response i was out of town for like a week.

I've installed a new Arch distro on my laptop and immediately installed min from the official repositories. So far i haven't yet encountered the issue again but will try to use @Casul51 script if the problems comes back.

Update:

I have encountered the problem again so i tried Casul51's script and it works. Thanks

@Syndamia Syndamia mentioned this issue Jan 4, 2021
@PalmerAL PalmerAL changed the title Youtube ads Youtube ads aren't blocked Jan 4, 2021
@PalmerAL PalmerAL pinned this issue Jan 4, 2021
@PalmerAL
Copy link
Collaborator

Adding a link to the userscript: https://greasyfork.org/en/scripts/407477-no-more-youtube-ads-updated/code

@iambudi
Copy link

iambudi commented May 10, 2021

Does the user script still valid? Since last two days i see that youtube ads show on playing.

@shubhxms
Copy link

Does the user script still valid? Since last two days i see that youtube ads show on playing.

Hey! I tried it today and it is working. :)

@shalva97
Copy link
Contributor

I have been having problems on this, I mean adds ;D

there is one add from my country that often shows up and is not blocked at all, but others like Gramarly and weird mobile games are skipped in about 1 seccond, which is fine...

image

@iambudi
Copy link

iambudi commented Aug 21, 2021

Hi, any workaround about this? Thank you.

@Ftwrr
Copy link

Ftwrr commented Aug 31, 2021

HI! I'm using userscript for this. Here it goes:

// ==UserScript==
// @name               No more youtube ads! - UPDATED
// @name:zh-CN         隐藏youtube google广告
// @namespace          FaZe BeeF
// @version            1.0.3
// @description        Automaticly Skips all youtube ads! with no waiting time.
// @description:zh-CN  BF5 : This skips all adds instantly. Youtube.com
// @author             FaZe BeeF
// @match              *://www.youtube.com/*
// ==/UserScript==

(function() {
    'use strict';
    var closeAd=function (){
        var css = '.video-ads .ad-container .adDisplay,#player-ads,.ytp-ad-module,.ytp-ad-image-overlay{ display: none!important; }',
            head = document.head || document.getElementsByTagName('head')[0],
            style = document.createElement('style');

        style.type = 'text/css';
        if (style.styleSheet){
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }

        head.appendChild(style);
    };
    var skipInt;
    var log=function(msg){
       // unsafeWindow.console.log (msg);
    };
    var skipAd=function(){
        //ytp-ad-preview-text
        //ytp-ad-skip-button
        var skipbtn=document.querySelector(".ytp-ad-skip-button.ytp-button")||document.querySelector(".videoAdUiSkipButton ");
        //var skipbtn=document.querySelector(".ytp-ad-skip-button ")||document.querySelector(".videoAdUiSkipButton ");
        if(skipbtn){
           skipbtn=document.querySelector(".ytp-ad-skip-button.ytp-button")||document.querySelector(".videoAdUiSkipButton ");
           log("skip");
           skipbtn.click();
           if(skipInt) {clearTimeout(skipInt);}
           skipInt=setTimeout(skipAd,500);
         }else{
              log("checking...");
              if(skipInt) {clearTimeout(skipInt);}
              skipInt=setTimeout(skipAd,500);
         }
    };

    closeAd();
    skipAd();

})();

how to use?

@eltoncezar
Copy link

@iambudi
Copy link

iambudi commented Oct 15, 2021

I have been having problems on this, I mean adds ;D

there is one add from my country that often shows up and is not blocked at all, but others like Gramarly and weird mobile games are skipped in about 1 seccond, which is fine...

Yes local ads unskippable in 1 second. I got 2 ads playing in a row.

@Syndamia
Copy link
Member

Yeah, YouTube has changed some things which make the script not work sometimes. And I couldn't find any other userscript that fixes that issue.

A somewhat viable alternative is using an invidious instance, like yewtu.be or inv.riverside.rocks. Those come with the added bonus that you can also watch age restricted videos, but have some feature drawbacks (feed isn't infinite, livestreams don't really work, ..). More complete list of trusted public instances here.

@lunatic-gh
Copy link

I'm going to ressurect this thing of an issue, and share a new script i found on the web, that works ootb without any issues for me on all videos currently.

// ==UserScript==
// @name         YouTube - Ad Skip
// @version      1.0
// @description  Skips and removes ads on YouTube automatically
// @author       Bobocato
// @match        https://www.youtube.com/*
// @grant        none
// @namespace https://greasyfork.org/users/167089
// ==/UserScript==

const equalText1 = "Skip Ads";
const equalText2 = "Skip Ad";

function addNewStyle(newStyle) {
    var styleElement = document.getElementById('styles_js');
    if (!styleElement) {
        styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.id = 'styles_js';
        document.getElementsByTagName('head')[0].appendChild(styleElement);
    }
    styleElement.appendChild(document.createTextNode(newStyle));
}

function skipAd(){
    console.log("Tried to skip a ad");
    if(document.getElementsByClassName("ytp-ad-skip-button").length > 0){
        if(document.getElementsByClassName("ytp-ad-skip-button")[0].childNodes[0].textContent === equalText1 || document.getElementsByClassName("ytp-ad-skip-button")[0].childNodes[0].textContent === equalText2){
            document.getElementsByClassName("ytp-ad-skip-button")[0].click();
        } else {
            setTimeout(skipAd(), 1000);
        }
    }
}

(function() {
    'use strict';
    addNewStyle('.ytp-ad-overlay-slot {display:none !important;}');
    setInterval(function (){
        if(window.location.href.substring(0,30) == "https://www.youtube.com/watch?"){
            skipAd();
        }
    }, 500);
})();

I modified a single value, which is the 500 at the bottom. It's the time in which period it constantly tries to skip ads as long as videos are playing. in my case, it searches every half a second for an ad, and skips it if it appears, no matter if the button says "skip in x seconds" or "skip now".

Now, 500 may seem a bit overkill. The default was at 1500, which i myself found a little too annoying. So yea, if you can spare the pc-performance like me, you can go lower than 1500, if you can't, you can always change it and restart your browser afterwards to update it.

@M-Arnone
Copy link

this one doesn't work for me but this one from Ftwrr works very well : #1121 (comment).

@javisgn
Copy link

javisgn commented Oct 21, 2023

Both the scripts doesn't work anymore, does someone have any solution?

@kepler-69c
Copy link

@javisgn This userscript works for me. Alternatively, GreasyFork is a good source of user scripts.

@alexventuraio
Copy link

@javisgn This userscript works for me. Alternatively, GreasyFork is a good source of user scripts.

I can confirm that it worked for me Min Version 1.31.1 (1.31.1) in MacOS Sonoma 14.2.1 (23C71).

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

No branches or pull requests