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.2
// @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 to log actions */
    const logAction = (action) => console.log(`[Ad Skipper] ${action}`);

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

        document.body.appendChild(notification);
        setTimeout(() => notification.remove(), 5000);
    };

    /** Check for Updates and Health of Script */
    const checkScriptHealth = async () => {
        try {
            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 version check
            const response = await fetch("https://update.greasyfork.org/scripts/519893/version-check");
            if (response.ok) {
                const data = await response.json();
                if (data.latestVersion && data.latestVersion !== "2.2") {
                    showNotification("A new version of the script is available. Please update!", "error");
                    logAction("Script update available notification displayed.");
                }
            } else {
                throw new Error("Failed to fetch update information.");
            }
        } catch (error) {
            console.error("[Ad Skipper] Error during health check:", error);
            showNotification("Error during script health check. Consider checking for updates.", "error");
        }
    };

    /** Skip Ads on YouTube */
    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 using selector: ${selector}`);
            });
        });
    };

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

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

    /** Initialize the Script */
    const init = () => {
        logAction("Initializing Ad Skipper...");
        showNotification("Ad Skipper script initialized!", "info");

        bypassAdBlocker();
        const observer = new MutationObserver(skipAds);
        observer.observe(document.body, { childList: true, subtree: true });

        // Periodic health check
        setInterval(checkScriptHealth, 60000);
    };

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