Greasy Fork

Greasy Fork is available in English.

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

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

目前为 2020-10-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         Youtube Ad Cleaner(Include Non-Skippable Ads- works)
// @namespace    http://tampermonkey.net/
// @version      1.43
// @description  (Support Chrome & Firefox) 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';

function adMonitor()
{
    try
    {
      let yt = document.getElementById("movie_player");
      if(yt !==undefined || yt !== null)
      {
          let ytAdState = yt.getAdState();
          if (ytAdState === 1)
          {
            console.log("Non-Skippable video Ad is found");
            yt.stopVideo();
            setTimeout(()=>{yt.playVideo();},1000);
          }
      }
    }
    catch(e)
    {
      return;
    }
}

function removeSp()
{
    try
    {
        if (document.getElementById("support").innerText.includes("Ad"))
        {
               let sp = document.getElementsByClassName("style-scope ytd-rich-grid-renderer");

                if(sp)
                {
                    sp[5].remove();
                }
            }
        }
    catch(e)
    {
        return;
    }
 }

var Ads = {
    "aId":["masthead-ad","player-ads","top-container","offer-module","pyv-watch-related-dest-url","ytd-promoted-video-renderer"],
    "aClass":["style-scope ytd-search-pyv-renderer","ytd-compact-promoted-video-renderer","style-scope ytd-carousel-ad-renderer","ytp-ad-overlay-container","style-scope ytd-popup-container","ytp-ad-message-container"],
    "aTag":["ytd-promoted-sparkles-text-search-renderer"],
    "vdoAd":["ytp-ad-text ytp-ad-preview-text","ytp-ad-skip-button ytp-button"],
    "removeByID":function(){this.aId.forEach(i=>{ let AdId = document.getElementById(i);if(AdId) AdId.remove();})},
    "removeByClassName":function(){this.aClass.forEach(c=>{ let AdClass = document.getElementsByClassName(c);if(AdClass[0]) AdClass[0].remove();})},
    "removeByTagName":function(){this.aTag.forEach(t=>{ let AdTag = document.getElementsByTagName(t);if(AdTag[0]) AdTag[0].remove();})},
    "removeVdoAd":function(){this.vdoAd.forEach(v=>{let AdVdo = document.getElementsByClassName(v)[0];if(AdVdo) AdVdo.click();})}
}

function killAd()
{
    Ads.removeByID();
    Ads.removeByClassName();
    Ads.removeByTagName();
    Ads.removeVdoAd();
    removeSp();
}

setInterval(adMonitor, 500);
setInterval(killAd, 10);