YouTube Auto Skip Ads

autoclicks on youtube's skip ad buttons once they appear, also auto-closes banner ads

2024-08-13 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         YouTube Auto Skip Ads
// @namespace    none
// @version      0.8
// @description  autoclicks on youtube's skip ad buttons once they appear, also auto-closes banner ads
// @author       RustyPrimeLUX
// @match        https://www.youtube.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var currentVideoTime = 0;

    var videoPlayer = document.querySelector(".video-stream.html5-main-video");
    var skipAdBtn = document.querySelector("div.ytp-ad-text.ytp-ad-skip-button-text") || document.querySelector(".ytp-skip-ad-button") || document.querySelector(".ytp-skip-ad-button__text");
    var closeBannerBtn = document.querySelector("button.ytp-ad-overlay-close-button");
    var errorScreen = document.querySelector("#error-screen");

    setInterval(function(){
        if (getVideoPlayer() && isVisible(videoPlayer)){
            var currentTime = Math.floor(videoPlayer.currentTime);
            if (currentTime > 30)
            {
                currentVideoTime = currentTime;
            }
        }

        if(getSkipAdsButton() && isVisible(skipAdBtn)){
            skipAdBtn.click();
        }

        if(getCloseBannerButton() && isVisible(closeBannerBtn)){
            closeBannerBtn.click();
        }

        if (getErrorScreen() && isVisible(errorScreen)){
            if (currentVideoTime == 0)
            {
                window.location.reload();
            }
            else{
                var currentLink = window.location.href;
                var playAtTimestampQuery = "&t=";

                if (currentLink.includes(playAtTimestampQuery)){
                    currentLink = currentLink.split(playAtTimestampQuery)[0];
                }

                var linkWithTimestamp = currentLink + playAtTimestampQuery + currentVideoTime;
                window.location.href = linkWithTimestamp;
            }
        }
    }, 1000);

    function getVideoPlayer(){
        if (videoPlayer == null || (videoPlayer != null && !document.body.contains(videoPlayer))){
            videoPlayer = document.querySelector(".video-stream.html5-main-video");
        }
        return videoPlayer != null;
    }

    function getSkipAdsButton() {
        if (skipAdBtn == null || (skipAdBtn != null && !document.body.contains(skipAdBtn))){
            skipAdBtn = document.querySelector("div.ytp-ad-text.ytp-ad-skip-button-text") || document.querySelector(".ytp-skip-ad-button") || document.querySelector(".ytp-skip-ad-button__text");
        }
        return skipAdBtn != null;
    }

    function getCloseBannerButton() {
        if (closeBannerBtn == null || (closeBannerBtn != null && !document.body.contains(closeBannerBtn))){
            closeBannerBtn = document.querySelector("button.ytp-ad-overlay-close-button");
        }
        return closeBannerBtn != null;
    }

    function getErrorScreen(){
        if (errorScreen == null || (errorScreen != null && !document.body.contains(errorScreen))){
            errorScreen = document.querySelector("#error-screen");
        }
        return errorScreen != null;
    }

    function isVisible(el) {
        return (el.offsetParent !== null)
    }
})();