Greasy Fork

Greasy Fork is available in English.

Youtube Ad Cleaner(Include Non-Skippable Ads- works)

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

目前为 2019-07-30 提交的版本。查看 最新版本

// ==UserScript==
// @name         Youtube Ad Cleaner(Include Non-Skippable Ads- works)
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// @namespace    http://tampermonkey.net/
// @version      1.30
// @description  Bypass all youtube ads including in video ads, skippable and non-skippable Ads
// @author       BjDanny
// @match        *://*.youtube.com/*
// ==/UserScript==

var home;
var myWin;
window.addEventListener("load", checkHome);
window.addEventListener("yt-navigate-start", checkHome);


function checkHome() {

if(window.location.href !=='https://www.youtube.com/'){
    home = false;
    console.log('At home =', home);

    var timer1 = setInterval(KillNoSkipAd,1000);
    var to1 = setTimeout(cfmReload,2000);
    var timer3 = setInterval(killInVideoAd,1000);
    setTimeout(killAd,1000);
    }
    else{
    home = true;
    console.log('timer1 cleared');
    clearInterval(timer1);
    if(to1){
    console.log('to1 cleared');
    clearTimeout(to1);
    }
    console.log('timer3 cleared');
    clearInterval(timer3);
    console.log('At home =', home);
    setTimeout(killAd,1000);
    }
}


function killAd(){
    try{
    if ($(".videoAdUiRedesign")[0] !==undefined){
        $(".video-stream").attr("src", "");
    }
    $("#player-ads").remove();
    $("#masthead-ad").remove();
    $("#offer-module").remove();
    $("#pyv-watch-related-dest-url").remove();
    console.log('Sponsored cards - removed');
    }
    catch(e){return;}
}

function KillNoSkipAd(){
    var ytplayer = document.getElementById("movie_player");
    try{
  var adChannelName = $('.ytp-title-channel-name')[0].text;
           if ($('.ad-showing') [0] !== undefined || adChannelName !==""){
            console.log('skipped in-video ad');
            ytplayer.cancelPlayback();
             setTimeout(ytplayer.playVideo(), 1000);
           }
    }catch(e){return;}
}

function cfmReload(){
    var ytplayer = document.getElementById("movie_player");
    try{
    var pauseOrNot = document.querySelector('.ytp-play-button.ytp-button').getAttribute('title');
     if (pauseOrNot == 'Pause (k)' && ytplayer.getCurrentTime() == 0){
        location.reload();
        fixLoop();
        console.log('Skipped Preload Video Ad');
     }}
catch(e){return;}}

function killInVideoAd(){
    try{
    if ($(".video-ads")[0] !== undefined){
       console.log('Overlay ads - removed');
        $(".video-ads").remove();
    }}catch(e){return;}
}

function fixLoop(){
   console.log('fixLoop is triggered');
   myWin = window.open('', '_blank');
   myWin.document.write("<script>function closeIt(){window.close();} window.onload=setTimeout(closeIt, 1000);<\/script><p>Skipping Ad ... auto close!!</p>");
   myWin.focus();
    }