Greasy Fork

Greasy Fork is available in English.

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

(Chrome ONLY) Bypass all youtube ads including in video ads, skippable and non-skippable Ads

当前为 2020-03-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Youtube Ad Cleaner(Include Non-Skippable Ads- works)
// @namespace    http://tampermonkey.net/
// @version      1.38.2
// @description  (Chrome ONLY) Bypass all youtube ads including in video ads, skippable and non-skippable Ads
// @author       BjDanny
// @run-at          document-start
// @match        *://*.youtube.com/*
// ==/UserScript==
'use strict';
setInterval(killAd,1);
window.addEventListener("DOMContentLoaded", checkHome);
window.addEventListener("yt-navigate-start", checkHome);

function fastHomeListener()
{
    var logo = document.getElementById('logo');
    if(logo)
    {
       logo.addEventListener("click", fasterBackHome);
       console.log('fastHomeListener is activated');
    }
}

function fasterBackHome()
{
    var ytplayer = document.getElementById("movie_player");
    ytplayer.cancelPlayback();
    console.log('Home logo is clicked');
    window.location.href = 'https://www.youtube.com';
}

function checkHome()
{
    if(window.location.href !=='https://www.youtube.com/')
    {
       var timer1 = setInterval(KillNoSkipAd,1);
       var timer2 = setInterval(killInVideoAd,1);
       var to1 = setTimeout(cfmReload,2000);
       var to2 = setTimeout(fastHomeListener, 1000);
    }
    else
    {
     clearInterval(timer1);
     clearInterval(timer2);
     clearTimeout(to1);
     clearTimeout(to2);
    }
}

function KillNoSkipAd()
{
    var ytplayer = document.getElementById("movie_player");
    var VdoTime;
    try{
           VdoTime = ytplayer.getCurrentTime();
           var adChannelName = document.getElementsByClassName('ytp-title-channel-name')[0].text;
           if (document.getElementsByClassName('ad-showing') [0] !== undefined || adChannelName !=="")
           {
                 console.log('skipped in-video ad');
                 ytplayer.cancelPlayback();
                 setTimeout(ytplayer.playVideo(), 1);
                 setTimeout(function(){if (ytplayer.getCurrentTime() == VdoTime){location.reload(); fixLoop(); console.log('Reloaded again !!!');}}, 4000);
            }
        }
     catch(e)
     {
         return;
      }
}

function killAd()
{
    removeByID();
    removeByClassName();
    removeByTagName();
}

function removeByID()
{
    var aId = ["masthead-ad","player-ads","top-container","offer-module","pyv-watch-related-dest-url","ytd-promoted-video-renderer"];
    for (var i in aId)
    {
          var AdId = document.getElementById(aId[i]);
          if (AdId !==null && AdId!==undefined)
          {
              AdId.remove();
           }
     }
}

function removeByClassName()
{
    var aClass = ["style-scope ytd-search-pyv-renderer","style-scope ytd-search-pyv-renderer"];
    for (var i in aClass)
    {
          var AdClass = document.getElementsByClassName(aClass[i]);
          if (AdClass[0] !==null && AdClass[0]!==undefined)
          {
              AdClass[0].remove();
           }
     }
}

function removeByTagName()
{
    var aTag = ["ytd-promoted-sparkles-text-search-renderer"];
    for (var i in aTag)
    {
          var AdTag = document.getElementsByTagName(aTag[i]);
          if (AdTag[0] !==null && AdTag[0]!==undefined)
          {
              AdTag[0].remove();
           }
     }
 }

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');
         }
        else
        {
            console.log('No preload video Ad. Good !');
        }
    }
    catch(e)
    {
        return;
    }
}

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

function fixLoop()
{
   console.log('fixLoop is triggered');
   let 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();
}