Greasy Fork is available in English.

YouTube Ad Skipper and Detection Bypass (Enhanced with Notifications)

Bypass YouTube's ad blocker detection, skip ads seamlessly, and notify if the script needs updating or stops working.

// ==UserScript==
// @name         YouTube Ad Skipper and Detection Bypass (Enhanced with Notifications)
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Bypass YouTube's ad blocker detection, skip ads seamlessly, and notify if the script needs updating or stops working.
// @author       ImprovedScript
// @match        *://*.youtube.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    /** Utility Functions */
    const logAction = (action) => {
        console.log(`[Ad Skipper] ${action}`);
    };

    /** Notification System */
    const showNotification = (message, type = "info") => {
        const notification = document.createElement("div");
        notification.style.position = "fixed";
        notification.style.bottom = "10px";
        notification.style.right = "10px";
        notification.style.zIndex = "9999";
        notification.style.backgroundColor = type === "error" ? "#ff4c4c" : "#4caf50";
        notification.style.color = "#fff";
        notification.style.padding = "15px";
        notification.style.borderRadius = "5px";
        notification.style.boxShadow = "0 2px 5px rgba(0, 0, 0, 0.3)";
        notification.style.fontFamily = "Arial, sans-serif";
        notification.style.fontSize = "14px";
        notification.innerText = message;

        document.body.appendChild(notification);

        setTimeout(() => {
            notification.remove();
        }, 5000);
    };

    /** Check if Script is Working */
    const checkScriptHealth = async () => {
        try {
            // Simulate a health check by verifying YouTube's critical elements
            const adElements = document.querySelectorAll(".ytp-ad-skip-button, .ytp-ad-overlay-close-button");
            if (adElements.length === 0) {
                logAction("No ads found to skip.");
            }

            // Simulate a fetch request to check for script updates
            const response = await fetch("https://update.greasyfork.org/scripts/519893/version-check");
            if (!response.ok) {
                throw new Error("Failed to fetch update information.");
            }
            const data = await response.json();
            const latestVersion = data.latestVersion || "2.1";
            if (latestVersion !== "2.1") {
                showNotification("A new version of the script is available. Please update!", "error");
                logAction("Script update notification displayed.");
            }
        } catch (error) {
            console.error("[Ad Skipper] Script encountered an error:", error);
            showNotification("The script encountered an issue. Check for updates or report the issue.", "error");
        }
    };

    /** Targeted Ad Skipping */
    const skipAds = () => {
        const adSelectors = [
            ".ytp-ad-skip-button",
            ".ytp-ad-overlay-close-button",
            ".ytp-ad-player-overlay",
            "div.ytp-ad-module",
        ];

        adSelectors.forEach((selector) => {
            document.querySelectorAll(selector).forEach((el) => {
                el.click();
                el.remove();
                logAction(`Skipped ad with selector: ${selector}`);
            });
        });
    };

    /** Ad Blocker Detection Bypass */
    const bypassAdBlocker = () => {
        const observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                mutation.addedNodes.forEach((node) => {
                    if (
                        node.nodeType === 1 &&
                        node.tagName === "YTD-POPUP-CONTAINER" &&
                        node.innerText.includes("ad blocker")
                    ) {
                        logAction("Removed ad blocker detection popup.");
                        node.remove();
                    }
                });
            });
        });

        observer.observe(document.body, { childList: true, subtree: true });
        logAction("Ad blocker bypass monitoring started.");
    };

    /** Initialization */
    const init = async () => {
        logAction("Initializing Ad Skipper...");
        showNotification("Ad Skipper script initialized successfully!", "info");

        bypassAdBlocker();

        const observer = new MutationObserver(() => {
            skipAds();
        });

        observer.observe(document.body, { childList: true, subtree: true });

        // Periodically check the health of the script
        setInterval(() => {
            checkScriptHealth();
        }, 60000); // Check every 60 seconds
    };

    // Run the script
    init();
})();