YouTube True Theater Mode

Apply a custom css when you enter theater mode in YouTube, hiding everything except the video.

目前為 2024-02-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube True Theater Mode
// @namespace    azb-truetheater
// @version      0.1
// @description  Apply a custom css when you enter theater mode in YouTube, hiding everything except the video.
// @author       Azb
// @match        https://www.youtube.com/*
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function applyCustomStyles() {
        const customCSS = `
            ytd-watch-flexy[theater] #player-full-bleed-container.ytd-watch-flexy,
            ytd-watch-flexy[theater] #full-bleed-container.ytd-watch-flexy {
                height: 100vh;
                max-height: none;
            }
            #masthead-container.ytd-app {
                margin-top: 1px;
                padding-bottom: 5px;
                opacity: 0;
                transition: margin 2000ms, padding 2000ms, opacity 400ms;
            }
            #masthead-container.ytd-app:hover {
                margin-top: 0;
                padding-bottom: 0;
                opacity: 1;
                background: #0f0f0f;
            }
            #page-manager.ytd-app {
                margin-top: -6px;
            }
            ytd-feed-filter-chip-bar-renderer[fluid-width] #chips-content.ytd-feed-filter-chip-bar-renderer {
                display: none;
            }
        `;
        const styleElement = document.createElement('style');
        styleElement.textContent = customCSS;
        styleElement.id = 'custom-youtube-styles';
        document.head.appendChild(styleElement);
    }

    function removeCustomStyles() {
        const styleElement = document.querySelector('#custom-youtube-styles');
        if (styleElement) {
            styleElement.remove();
        }
    }

    function toggleCustomStyles() {
        const styleElement = document.querySelector('#custom-youtube-styles');
        if (styleElement) {
            removeCustomStyles();
        } else {
            applyCustomStyles();
        }
    }

    const theaterButton = document.querySelector('.ytp-size-button');
    if (theaterButton) {
        theaterButton.addEventListener('click', toggleCustomStyles);
    }
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.type === 'attributes' && mutation.attributeName === 'theater') {
                if (!mutation.target.hasAttribute('theater')) {
                    removeCustomStyles();
                }
            }
        });
    });

    const targetNode = document.querySelector('ytd-watch-flexy');
    if (targetNode) {
        observer.observe(targetNode, {
            attributes: true
        });
    }
})();