// ==UserScript== // @name YouTube Maximizer 網頁全螢幕 // @namespace http://tampermonkey.net/ // @homepageURL https://github.com/kevinboy666/YouTube-Maximizer // @license MIT // @version 1.6 // @description Maximizes the YouTube player to fill the entire browser viewport when in theater mode // @author sharlxeniy // @match https://www.youtube.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com // @grant none // @downloadURL https://update.greasyfork.icu/scripts/528565/YouTube%20Maximizer%20%E7%B6%B2%E9%A0%81%E5%85%A8%E8%9E%A2%E5%B9%95.user.js // @updateURL https://update.greasyfork.icu/scripts/528565/YouTube%20Maximizer%20%E7%B6%B2%E9%A0%81%E5%85%A8%E8%9E%A2%E5%B9%95.meta.js // ==/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 removeStyles() { const style = document.querySelector('#custom-youtube-style'); if (style) style.remove(); } function isWatchPage() { return location.pathname === '/watch'; } function updateStyles() { if (isWatchPage() && document.cookie.includes('wide=1')) { addStyles(); window.addEventListener('scroll', handleScroll); } else { removeStyles(); window.removeEventListener('scroll', handleScroll); } } 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'; } } function dismissPromo() { const dismissButton = document.querySelector('#dismiss-button button'); if (dismissButton) { console.log('發現Premium廣告,自動關閉'); dismissButton.click(); } } const observer = new MutationObserver(() => { updateStyles(); dismissPromo(); }); observer.observe(document.body, { childList: true, subtree: true }); })();