Greasy Fork is available in English.

YouTube Ad Skipper and Detection Bypass (Enhanced for Mobile)

Bypass YouTube's ad blocker detection, skip ads seamlessly on both desktop and mobile, and notify users about updates or issues.

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         YouTube Ad Skipper and Detection Bypass (Enhanced for Mobile)
// @namespace    http://tampermonkey.net/
// @version      2.3
// @description  Bypass YouTube's ad blocker detection, skip ads seamlessly on both desktop and mobile, and notify users about updates or issues.
// @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: "10px",
            borderRadius: "4px",
            fontFamily: "Arial, sans-serif",
            fontSize: "12px",
            width: "calc(100% - 20px)", // Mobile-friendly width
            maxWidth: "300px", // Limit to desktop-friendly width
            textAlign: "center",
        });

        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.3") {
                    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.");
    };

    /** Adjust for Mobile Specific Layouts */
    const adaptToMobile = () => {
        // Ensure notifications and actions are adjusted for touch-friendly interfaces
        const metaViewport = document.querySelector('meta[name="viewport"]');
        if (!metaViewport) {
            const viewport = document.createElement("meta");
            viewport.name = "viewport";
            viewport.content = "width=device-width, initial-scale=1";
            document.head.appendChild(viewport);
            logAction("Viewport meta tag added for mobile compatibility.");
        }
    };

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

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

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

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