Hide youtube google ad

hide youtube google ad,auto click "skip ad"

Verze ze dne 28. 03. 2018. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name               Hide youtube google ad
// @name:zh-CN         隐藏youtube google广告
// @namespace          vince.youtube
// @version            2.1.0
// @description        hide youtube google ad,auto click "skip ad"
// @description:zh-CN  隐藏youtube显示的google广告,自动点击"skip ad"
// @author             vince ding
// @match              *://www.youtube.com/*
// ==/UserScript==

(function() {
    'use strict';
    var closeAd=function (){
        var css = '.video-ads .ad-container .adDisplay,#player-ads{ 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 skiptxt=document.querySelector(".ytp-ad-preview-text");
        if(skiptxt){
            var skipText=skiptxt.innerText;
            log(skipText);
            var _textAry=skipText.split(" ");
            var sec=(_textAry.length>0?_textAry[_textAry.length-1]:1);
            log(sec);
            if((sec-1)>0){
                log("wait btn...");
                if(skipInt) {clearTimeout(skipInt);}
                skipInt=setTimeout(skipAd,500);
            }else{
                var skipbtn=document.querySelector(".ytp-ad-skip-button");
                if(skipbtn){
                    log("close ad");
                    skipbtn.click();
                }
                log("checking...");
                if(skipInt) {clearTimeout(skipInt);}
                skipInt=setTimeout(skipAd,500);
            }
        }else{
            log("checking skip text...");
            if(skipInt) {clearTimeout(skipInt);}
            skipInt=setTimeout(skipAd,500);
        }
    };

    closeAd();
    skipAd();

})();