Bypass YouTube Account-Based Restrictions

This scripts will not restore your account from a restricted status!

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Bypass YouTube Account-Based Restrictions
// @namespace    https://greasyfork.org
// @version      0.0.6
// @description  This scripts will not restore your account from a restricted status!
// @author       Pixmi
// @homepage     https://github.com/Pixmi/bypass-youtube-account-based-restrictions
// @supportURL   https://github.com/Pixmi/bypass-youtube-account-based-restrictions/issues
// @match        https://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @license      GPL-3.0
// @grant        none
// @compatible   Chrome
// @compatible   Firefox
// ==/UserScript==

(function() {
    'use strict';

    let lastUrl = location.href;

    const observeUrlChange = async () => {
        if (location.href === lastUrl) return;
        lastUrl = location.href;
        // console.log('URL changed to:', lastUrl);
        await replacePlayer(lastUrl);
    };

    const titleNode = document.querySelector('title');
    if (titleNode) {
        new MutationObserver(observeUrlChange).observe(titleNode, { childList: true });
    }

    const progressNode = document.querySelector('yt-page-navigation-progress');
    if (progressNode) {
        new MutationObserver(observeUrlChange).observe(progressNode, { attributes: true });
    }

    async function replacePlayer(url) {
        const match = url.match(/(?<type>watch|live|shorts)(?:\?v=|\/)(?<id>.{11})/) || false;
        if (!match) {
            document.body.querySelector('iframe.embed-frame')?.setAttribute('src', '');
            return false;
        }
        const attributes = {
            src: `https://www.youtube.com/embed/${match.groups.id}?autoplay=0&modestbranding=1`,
            title: 'YouTube video player',
            class: 'embed-frame',
            frameborder: 0,
            allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share',
            referrerpolicy: 'strict-origin-when-cross-origin',
            allowfullscreen: ''
        }
        if (/m\.youtube/.test(url)) {
            attributes.id = 'movie_player';
            attributes.class += ' html5-video-player';
            document.querySelector('#player-container-id #player')?.setAttribute('playable', 'true');
        } else {
            attributes.id = match.groups.type == 'shorts' ? 'shorts-player' : 'ytd-player';
            attributes.style = 'width:100%;height:100%;visibility:visible!important;';
            document.querySelector('yt-playability-error-supported-renderers')?.setAttribute('style', 'display:none;');
        }
        const player = document.querySelector(`#${attributes.id}`);
        if (player.src === attributes.src) return false;
        const frame = document.createElement('iframe');
        for (const key of Object.keys(attributes)) frame.setAttribute(key, attributes[key]);
        player.replaceWith(frame);
    }

    setTimeout(async () => await replacePlayer(lastUrl), 2000);

    document.addEventListener('visibilitychange', async () => {
        if (document.visibilityState === 'visible') {
            await replacePlayer(lastUrl)
        }
    });
})();