YouTube Restriction Bypass

Bypass age/content restrictions on YouTube

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         YouTube Restriction Bypass
// @namespace    https://greasyfork.org/en/users/305931-emerson-bardusco
// @version      1.7
// @description  Bypass age/content restrictions on YouTube
// @author       EmersonxD
// @match        *://*.youtube.com/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    var config = {
        proxyHost: 'https://youtube-proxy.zerody.one',
        validStatuses: ['OK', 'LIVE_STREAM_OFFLINE'],
        unlockableStatuses: ['AGE_VERIFICATION_REQUIRED', 'CONTENT_CHECK_REQUIRED']
    };

    var nativeXHR = XMLHttpRequest.prototype.open;
    var nativeJSON = JSON.parse;

    function log() {
        var args = Array.prototype.slice.call(arguments);
        console.log('[Bypass] ' + args.join(' '));
    }

    function isGoogleVideo(url) {
        return url.host.indexOf('.googlevideo.com') > -1;
    }

    function needsProxy(url) {
        return url.search.indexOf('gcr=') > -1;
    }

    function buildProxyUrl(url) {
        return config.proxyHost + '/direct/' + btoa(url.href);
    }

    function modifyRequest(url) {
        if (!isGoogleVideo(url)) return url.href;
        if (!needsProxy(url)) return url.href;
        
        try {
            return buildProxyUrl(url);
        } catch(e) {
            log('Error modifying request:', e.message);
            return url.href;
        }
    }

    function unlockPlayer(data) {
        var status = data.playabilityStatus;
        if (status && config.unlockableStatuses.indexOf(status.status) > -1) {
            status.status = 'OK';
            status.reason = '';
            log('Player unlocked');
        }
        return data;
    }

    function unlockResponse(data) {
        var content = data.contents;
        if (content && content.twoColumnWatchNextResults && content.twoColumnWatchNextResults.secondaryResults) {
            content.twoColumnWatchNextResults.secondaryResults = { 
                secondaryResults: { 
                    results: [] 
                } 
            };
            log('Sidebar cleaned');
        }
        return data;
    }

    function processJSON(data) {
        try {
            return unlockResponse(unlockPlayer(data));
        } catch(e) {
            log('Processing error:', e.message);
            return data;
        }
    }

    XMLHttpRequest.prototype.open = function(method, url) {
        var newUrl = modifyRequest(new URL(url));
        var args = [method, newUrl || url].concat(Array.prototype.slice.call(arguments, 2));
        nativeXHR.apply(this, args);
    };

    JSON.parse = function(text) {
        return processJSON(nativeJSON.call(this, text));
    };

    log('Initialized');
})();