Ultimate YouTube Age restriction bypass PRO. Add skipper and more

Seamlessly bypass YouTube's age restriction and skip ads. Self-updates for future compatibility! 🚀

目前為 2025-01-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Ultimate YouTube Age restriction bypass PRO. Add skipper and more
// @description  Seamlessly bypass YouTube's age restriction and skip ads. Self-updates for future compatibility! 🚀
// @version      6.0.0
// @namespace    https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/
// @license      MIT
// @match        https://www.youtube.com/*
// @match        https://www.youtube-nocookie.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_notification
// @grant        GM_addStyle
// @run-at       document-start
// @compatible   chrome
// @compatible   firefox
// @compatible   edge
// ==/UserScript==

(function () {
    'use strict';

    /**
     * Configuration for the script
     */
    const CONFIG = {
        ENABLE_NOTIFICATIONS: true, // Show notifications for script events
        ENABLE_AUTO_AD_SKIP: true, // Automatically skip ads
        DEFAULT_VIDEO_QUALITY: '1080p', // Default playback quality
        CHECK_FOR_UPDATES_INTERVAL: 86400000, // Check for updates every 24 hours (in milliseconds)
        SCRIPT_UPDATE_URL: 'https://raw.githubusercontent.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass/main/bypass.user.js',
        PLAYABILITY_STATUSES_TO_UNLOCK: ['AGE_VERIFICATION_REQUIRED', 'CONTENT_WARNING']
    };

    const logger = {
        log: (...messages) => console.log('[YouTube Bypass]', ...messages),
        error: (...messages) => console.error('[YouTube Bypass]', ...messages),
        warn: (...messages) => console.warn('[YouTube Bypass]', ...messages)
    };

    /**
     * Show notifications if enabled
     */
    function showNotification(message, duration = 5000) {
        if (!CONFIG.ENABLE_NOTIFICATIONS) return;

        GM_notification({
            text: message,
            title: 'YouTube Bypass',
            timeout: duration / 1000
        });
    }

    /**
     * Automatically skip YouTube ads
     */
    function autoSkipAds() {
        if (!CONFIG.ENABLE_AUTO_AD_SKIP) return;

        const observer = new MutationObserver(() => {
            // Detect skip button or ad overlays
            const skipButton = document.querySelector('.ytp-ad-skip-button') ||
                document.querySelector('.ytp-ad-overlay-close-button');

            if (skipButton) {
                skipButton.click();
                logger.log('Ad skipped.');
                showNotification('Ad skipped!');
            }
        });

        // Observe DOM changes on the player
        observer.observe(document.body, { childList: true, subtree: true });
    }

    /**
     * Modify YouTube API responses to unlock videos
     */
    function interceptPlayerRequests() {
        const originalOpen = XMLHttpRequest.prototype.open;

        XMLHttpRequest.prototype.open = function (method, url, ...args) {
            if (url.includes('/youtubei/v1/player')) {
                this.addEventListener('readystatechange', function () {
                    if (this.readyState === 4 && this.status === 200) {
                        try {
                            const response = JSON.parse(this.responseText);
                            if (CONFIG.PLAYABILITY_STATUSES_TO_UNLOCK.includes(response?.playabilityStatus?.status)) {
                                logger.log('Unlocking restricted video...');
                                showNotification('Unlocking restricted video...');
                                response.playabilityStatus.status = 'OK'; // Unlock
                                this.responseText = JSON.stringify(response);
                            }
                        } catch (err) {
                            logger.error('Failed to process API response:', err);
                        }
                    }
                });
            }
            originalOpen.call(this, method, url, ...args);
        };
    }

    /**
     * Self-updating mechanism to fetch and apply latest script
     */
    function checkForUpdates() {
        const lastUpdateCheck = GM_getValue('lastUpdateCheck', 0);
        const now = Date.now();

        if (now - lastUpdateCheck < CONFIG.CHECK_FOR_UPDATES_INTERVAL) {
            return; // Skip if update was recently checked
        }

        GM_setValue('lastUpdateCheck', now);

        GM_xmlhttpRequest({
            method: 'GET',
            url: CONFIG.SCRIPT_UPDATE_URL,
            onload(response) {
                if (response.status === 200 && response.responseText.includes('// ==UserScript==')) {
                    const latestScript = response.responseText;
                    const currentVersion = GM_info.script.version;
                    const latestVersion = latestScript.match(/@version\s+([\d.]+)/)[1];

                    if (latestVersion !== currentVersion) {
                        logger.log(`Updating to version ${latestVersion}`);
                        GM_setValue('latestScript', latestScript);

                        // Apply the update
                        GM_notification({
                            text: 'A new version is available. Please reload the page to apply the update.',
                            title: 'YouTube Bypass Update',
                            onclick: () => location.reload()
                        });
                    } else {
                        logger.log('Script is up to date.');
                    }
                } else {
                    logger.error('Failed to fetch latest script version.');
                }
            },
            onerror() {
                logger.error('Error while checking for updates.');
            }
        });
    }

    /**
     * Apply the latest script if available
     */
    function applyLatestScript() {
        const latestScript = GM_getValue('latestScript', null);
        if (latestScript) {
            const scriptBlob = new Blob([latestScript], { type: 'application/javascript' });
            const scriptURL = URL.createObjectURL(scriptBlob);

            const scriptTag = document.createElement('script');
            scriptTag.src = scriptURL;
            document.head.appendChild(scriptTag);

            logger.log('Applied latest script version.');
        }
    }

    /**
     * Initialize the script
     */
    function initialize() {
        logger.log('Initializing YouTube Bypass script...');
        applyLatestScript();
        interceptPlayerRequests();
        autoSkipAds();
        checkForUpdates();
        logger.log('Initialization complete.');
    }

    initialize();
})();