YouTube Maximizer

Maximizes the YouTube player to fill the entire browser viewport when in theater mode

当前为 2025-03-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Maximizer
// @namespace    http://tampermonkey.net/
// @license     MIT
// @version      1.3
// @description  Maximizes the YouTube player to fill the entire browser viewport when in theater mode
// @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 styleSheet = `
        #masthead-container {
            transition: opacity 0.3s ease;
            opacity: 0; /* 初始隐藏顶部导航栏 */
            pointer-events: none;
        }
        #page-manager {
            margin-top: 0 !important;
        }
        #full-bleed-container {
            height: 100vh !important; /* 填满屏幕 */
            max-height: 100vh !important;
        }
        #movie_player {
            width: 100vw !important; /* 视频宽度为全屏 */
            height: 100vh !important; /* 视频高度为全屏 */
        }
    `;

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

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

    function updateStyles() {
        if (document.cookie.includes('wide=1')) {
            addStyles();
        } else {
            const style = document.querySelector('#custom-youtube-style');
            if (style) style.remove();
        }
    }

    function dismissPromo() {
        const dismissButton = document.querySelector('#dismiss-button button');
        if (dismissButton) {
            console.log('发现广告,自动关闭');
            dismissButton.click();
        }
    }

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

        if (window.scrollY > 0) {
            navbar.style.opacity = '1';
            navbar.style.pointerEvents = 'auto';
        } else {
            navbar.style.opacity = '0';
            navbar.style.pointerEvents = 'none';
        }
    }

    if (isWatchPage()) {
        updateStyles();
        dismissPromo();
        const observer = new MutationObserver(() => {
            updateStyles();
            dismissPromo();
        });
        observer.observe(document.body, { childList: true, subtree: true });
        window.addEventListener('scroll', handleScroll);
    }
})();