YouTube Maximizer 網頁全螢幕

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

  1. // ==UserScript==
  2. // @name YouTube Maximizer 網頁全螢幕
  3. // @namespace http://tampermonkey.net/
  4. // @homepageURL https://github.com/kevinboy666/YouTube-Maximizer
  5. // @license MIT
  6. // @version 1.6
  7. // @description Maximizes the YouTube player to fill the entire browser viewport when in theater mode
  8. // @author sharlxeniy <sharlxeniy@gmail.com>
  9. // @match https://www.youtube.com/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  11. // @grant none
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15.  
  16. // 定义样式表
  17. const styleSheet = `
  18. #masthead-container {
  19. transition: opacity 0.3s ease;
  20. opacity: 0; /* 隱藏頂部導覽 */
  21. pointer-events: none;
  22. }
  23. #page-manager {
  24. margin-top: 0 !important;
  25. }
  26. #full-bleed-container {
  27. height: 100vh !important; /* 填滿螢幕 */
  28. max-height: 100vh !important;
  29. }
  30. #movie_player {
  31. width: 100vw !important; /* 影片寬度全螢幕 */
  32. height: 100vh !important; /* 影片高度全螢幕 */
  33. }
  34. `;
  35.  
  36. function addStyles() {
  37. if (!document.querySelector('#custom-youtube-style')) {
  38. const style = document.createElement('style');
  39. style.id = 'custom-youtube-style';
  40. style.textContent = styleSheet;
  41. document.head.appendChild(style);
  42. }
  43. }
  44.  
  45. function removeStyles() {
  46. const style = document.querySelector('#custom-youtube-style');
  47. if (style) style.remove();
  48. }
  49.  
  50. function isWatchPage() {
  51. return location.pathname === '/watch';
  52. }
  53.  
  54. function updateStyles() {
  55. if (isWatchPage() && document.cookie.includes('wide=1')) {
  56. addStyles();
  57. window.addEventListener('scroll', handleScroll);
  58. } else {
  59. removeStyles();
  60. window.removeEventListener('scroll', handleScroll);
  61. }
  62. }
  63.  
  64. function handleScroll() {
  65. const navbar = document.querySelector('#masthead-container');
  66. if (!navbar) return;
  67.  
  68. if (window.scrollY > 0) {
  69. navbar.style.opacity = '1';
  70. navbar.style.pointerEvents = 'auto';
  71. } else {
  72. navbar.style.opacity = '0';
  73. navbar.style.pointerEvents = 'none';
  74. }
  75. }
  76.  
  77. function dismissPromo() {
  78. const dismissButton = document.querySelector('#dismiss-button button');
  79. if (dismissButton) {
  80. console.log('發現Premium廣告,自動關閉');
  81. dismissButton.click();
  82. }
  83. }
  84.  
  85. const observer = new MutationObserver(() => {
  86. updateStyles();
  87. dismissPromo();
  88. });
  89. observer.observe(document.body, { childList: true, subtree: true });
  90.  
  91. })();