Youtube Ad Cleaner(Include Non-Skipable Ads)

Bypass all youtube ads including in video ads, skipable and non-skipable Ads

目前為 2019-06-29 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Youtube Ad Cleaner(Include Non-Skipable Ads)
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// @namespace    http://tampermonkey.net/
// @version      1.25
// @description  Bypass all youtube ads including in video ads, skipable and non-skipable Ads
// @author       BjDanny
// @match        https://www.youtube.com/*
// ==/UserScript==
// The script runs in the backgound, monitoring all youtube ads.
// When non-skipable ads are found, the script will redirect the browser to previous page and then revisits the current URL.
// Depends on the amount of non-skipable ads, the browser may refresh couple times automatically.


var checkTimers;
var videoOnPauseState;
var atHome;
setInterval(killAd, 4000);
setInterval(isAtHome, 4000);
checker();

function videoOnPause(){
     var pauseOrNot;
     $(document).ready(function(){ pauseOrNot =document.querySelector('.ytp-play-button.ytp-button').getAttribute('title');});
    atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
    if (pauseOrNot == "Play (k)" && atHome === false ){
              return true ;
                       }
    else  {
               return false;
             }
}

function isAtHome(){
    if(window.location.href == 'https://www.youtube.com/'){
        return true;
        }
    else{
        return false;
        }
}

function checker(){
    setInterval(mainTimer, 1000);
    setInterval(directSkipAd, 2000);
    setInterval(logMsg, 1000);
}

function logMsg(){
         atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
         checkTimers = mainTimer(); //must include this statement,otherwise the return result will be wrong
//         console.log('Main timers running is ' + checkTimers);
//         console.log('video paused is ' + videoOnPauseState);
//         console.log('At Home page is ' + atHome);
//         console.log('Current Url is ' + window.location.href);
         if (checkTimers === false){
                console.log('2 timers are stopped');
         }
         else{
               console.log('All timers are running');
         }}

function mainTimer(){
    var timer1 = setInterval(KillNoSkipAd, 1000);
    var timer2 = setInterval(killInVideoAd, 1000);
    videoOnPauseState = videoOnPause(); //must include this statement, otherwise the return result will be wrong
    atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
    if(atHome === true || videoOnPauseState ===true) {
                              clearInterval(timer1);
                              clearInterval(timer2);
                              return false;
                              }
   else{
           return true;
        }
}

function killAd(){
    if ($(".videoAdUiRedesign")[0] !==undefined){
        $(".video-stream").attr("src", "");
    }
    $("#player-ads").remove();
    $("#masthead-ad").remove();
    $("#offer-module").remove();
    $(".video-ads").remove();
    $("#pyv-watch-related-dest-url").remove();
}



function KillNoSkipAd(){
    atHome = isAtHome(); //must include this statement, otherwise the return result will be wrong
    var ytplayer = document.getElementById("movie_player");
    var adChannelName = $('.ytp-title-channel-name')[0].text;
    var VTime = Math.round(ytplayer.getCurrentTime());
    var VideoURL = ytplayer.getVideoUrl();
    if(!atHome){
           if ($('.ad-showing') [0] !== undefined || adChannelName !==""){
           window.location = VideoURL;
    }
     }
}


function killInVideoAd(){
    if ($(".video-ads")[0] !== undefined){
        console.log('An in-video ad was removed');
        $(".video-ads").remove();
    }
}

function directSkipAd(){
       if( document.querySelector('.ytp-ad-text.ytp-ad-skip-button-text') !== null ){
                   document.querySelector('.ytp-ad-text.ytp-ad-skip-button-text').click();
     }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址