YouTubeシアターモード全画面

YouTube シアターモードを自動的に全画面表示にし、Premiumのアップグレード表示を非表示にします。

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         YouTube Theater Mode Fullscreen
// @name:zh-TW   YouTube 劇院模式全螢幕
// @name:zh-CN   YouTube 剧院模式全屏
// @name:ja      YouTubeシアターモード全画面
// @namespace    http://tampermonkey.net/
// @homepageURL  https://github.com/kevinboy666/YouTube-Maximizer
// @license      MIT
// @version      1.11
// @description  Automatically expand YouTube Theater Mode to full window and hide Premium upsell banners.
// @description:zh-TW 自動將 YouTube 劇院模式擴展為全視窗,並隱藏 Premium 升級提示。
// @description:zh-CN 自动将 YouTube 剧院模式扩展为全屏,并隐藏 Premium 升级提示。
// @description:ja    YouTube シアターモードを自動的に全画面表示にし、Premiumのアップグレード表示を非表示にします。
// @author       sharlxeniy <[email protected]>
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    // 定义样式表
    const videoStyleSheet = `
        #page-manager {
            margin-top: 0 !important;
        }
        #full-bleed-container {
            height: 100vh !important; /* 填滿螢幕 */
            max-height: 100vh !important;
        }
        #movie_player {
            width: 100vw !important; /* 影片寬度全螢幕 */
            height: 100vh !important; /* 影片高度全螢幕 */
        }
    `;

    const liveStyleSheet = `
        #page-manager {
            margin-top: 0 !important;
        }
        #full-bleed-container {
            height: 100vh !important; /* 填滿螢幕 */
            max-height: 100vh !important;
        }
        #movie_player {
            width: 70vw !important; /* 影片寬度全螢幕 */
            height: 100vh !important; /* 影片高度全螢幕 */
        }
    `;
    // 定義隱藏和顯示 navbar 的樣式
    const navbarClassStyle = `
#masthead-container.navbar-hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease;
}
#masthead-container.navbar-visible {
    opacity: 1 !important;
    pointer-events: auto !important;
    transition: opacity 0.3s ease;
}
`;

    function addVideoStyles() {
        if (!document.querySelector('#custom-youtube-style')) {
            const style = document.createElement('style');
            style.id = 'custom-youtube-style';
            style.textContent = videoStyleSheet;
            document.head.appendChild(style);
        }
    }

    function addLiveStyles() {
        if (!document.querySelector('#custom-youtube-style')) {
            const style = document.createElement('style');
            style.id = 'custom-youtube-style';
            style.textContent = liveStyleSheet;
            document.head.appendChild(style);
        }
    }

    function removeStyles() {
        const style = document.querySelector('#custom-youtube-style');
        if (style) style.remove();
    }

    function removeNavbarStyle() {
        const navbar = document.querySelector('#masthead-container');
        if (navbar) {
            navbar.classList.remove('navbar-hidden', 'navbar-visible');
        }
    }

    function isWatchPage() {
        return location.pathname === '/watch';
    }


    function updateStyles() {
        window.removeEventListener('scroll', handleScroll);
        if(document.cookie.includes('wide=1')){
            // 先處理直播聊天室情況
            if (isLive) {
                handleScroll();
                if (document.querySelector('#show-hide-button[hidden]')) {
                    // 聊天室可見 → 縮小影片避免擋住
                    console.log("聊天室可見");
                    removeStyles();
                    addLiveStyles();
                    console.log("使用直播");
                } else {
                    // 聊天室隱藏 → 恢復全寬
                    console.log("聊天室隱藏");
                    removeStyles();
                    addVideoStyles();
                    console.log("使用影片");
                }
                window.addEventListener('scroll', handleScroll);
            }
            else if (isWatchPage()) {
                handleScroll();
                addVideoStyles();
                window.addEventListener('scroll', handleScroll);
                console.log("使用影片");
            } else {
                removeStyles();
                removeNavbarStyle();
                console.log("不是影片,移除樣式");
                window.removeEventListener('scroll', handleScroll);
            }
        }
        else {
            removeStyles();
            removeNavbarStyle();
            console.log("劇院關閉,移除樣式")
            window.removeEventListener('scroll', handleScroll);
        }
    }

    function addNavbarClassStyles() {
        if (!document.querySelector('#navbar-class-style')) {
            const style = document.createElement('style');
            style.id = 'navbar-class-style';
            style.textContent = navbarClassStyle;
            document.head.appendChild(style);
        }
    }
    addNavbarClassStyles();

    function handleScroll() {
        const navbar = document.querySelector('#masthead-container');
        if (!navbar) return;

        if (window.scrollY > 0) {
            navbar.classList.add('navbar-visible');
            navbar.classList.remove('navbar-hidden');
        } else {
            navbar.classList.add('navbar-hidden');
            navbar.classList.remove('navbar-visible');
        }
    }

    function dismissPromo() {
        const dismissButton = document.querySelector('#dismiss-button button');
        if (dismissButton) {
            console.log('發現Premium廣告,自動關閉');
            dismissButton.click();
        }
    }

    function isLiveStream() {
        if (window.ytInitialPlayerResponse &&
            window.ytInitialPlayerResponse.videoDetails) {
            return !!window.ytInitialPlayerResponse.videoDetails.isLiveContent;
        }
        return false;
    }

    let isLive = false;
    function checkIsLiveStream() {
        if (window.ytInitialPlayerResponse) {
            isLive = isLiveStream();
            console.log("是否為直播:", isLive);
        } else {
            // 如果還沒有載入,稍後再試
            setTimeout(checkIsLiveStream, 500);
        }
    }
    checkIsLiveStream();


    const observer = new MutationObserver(() => {
        updateStyles();
        dismissPromo();
    });


    observer.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['hidden']
        //attributeFilter: ['style', 'class', 'hidden', 'display', 'visibility']
    });
    
})();