Advanced YouTube Age Restriction Bypass

Bypass YouTube age restrictions for test purposes only.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Advanced YouTube Age Restriction Bypass
// @namespace    http://tampermonkey.net/
// @version      3.0
// @description  Bypass YouTube age restrictions for test purposes only.
// @author       Your Name
// @match        *://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Helper function to log debug messages
    function log(message) {
        console.log(`[YouTube Bypass]: ${message}`);
    }

    // Hook into YouTube's internal API requests
    (function interceptXHR() {
        const originalOpen = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function(method, url) {
            if (url.includes('/youtubei/v1/player')) {
                log('Intercepted YouTube player API request');
                this.addEventListener('readystatechange', function() {
                    if (this.readyState === 4 && this.status === 200) {
                        try {
                            const response = JSON.parse(this.responseText);
                            if (response.playabilityStatus?.status === 'AGE_RESTRICTED') {
                                log('Detected age-restricted video. Modifying response...');
                                response.playabilityStatus.status = 'OK';
                                response.playabilityStatus.reason = '';
                                Object.defineProperty(this, 'responseText', { value: JSON.stringify(response) });
                            }
                        } catch (e) {
                            log('Error modifying API response: ' + e.message);
                        }
                    }
                });
            }
            return originalOpen.apply(this, arguments);
        };
    })();

    // MutationObserver to monitor dynamic page changes (SPA handling)
    const observer = new MutationObserver(() => {
        if (document.querySelector('ytd-watch-flexy[is-restricted]')) {
            log('Detected restricted video player. Attempting bypass...');
            injectOverrideScript();
        }
    });

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

    // Function to inject an override script directly into the page
    function injectOverrideScript() {
        const script = document.createElement('script');
        script.innerHTML = `
            (function() {
                const originalPlayer = window.ytPlayerConfig;
                if (originalPlayer && originalPlayer.args) {
                    originalPlayer.args.raw_player_response.playabilityStatus.status = 'OK';
                    console.log('[YouTube Bypass]: Player configuration modified.');
                }
            })();
        `;
        document.body.appendChild(script);
        script.remove();
    }

    log('Script initialized. Watching for restricted videos...');
})();