YouTube Maximizer

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

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

  1. // ==UserScript==
  2. // @name YouTube Maximizer
  3. // @namespace http://tampermonkey.net/
  4. // @license MIT
  5. // @version 1.1
  6. // @description Maximizes the YouTube player to fill the entire browser viewport when in theater mode
  7. // @author sharlxeniy <sharlxeniy@gmail.com>
  8. // @match https://www.youtube.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  10. // @grant none
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. // 定义样式表
  16. const styleSheet = `
  17. #masthead-container {
  18. transition: opacity 0.3s ease;
  19. opacity: 0; /* 初始隐藏顶部导航栏 */
  20. pointer-events: none;
  21. }
  22. #page-manager {
  23. margin-top: 0 !important;
  24. }
  25. #full-bleed-container {
  26. height: 100vh !important; /* 填满屏幕 */
  27. max-height: 100vh !important;
  28. }
  29. #movie_player {
  30. width: 100vw !important; /* 视频宽度为全屏 */
  31. height: 100vh !important; /* 视频高度为全屏 */
  32. }
  33. `;
  34.  
  35. function addStyles() {
  36. if (!document.querySelector('#custom-youtube-style')) {
  37. const style = document.createElement('style');
  38. style.id = 'custom-youtube-style';
  39. style.textContent = styleSheet;
  40. document.head.appendChild(style);
  41. }
  42. }
  43.  
  44. function isWatchPage() {
  45. return location.pathname === '/watch';
  46. }
  47.  
  48. function updateStyles() {
  49. if (isWatchPage() && document.cookie.includes('wide=1')) {
  50. addStyles();
  51. } else {
  52. const style = document.querySelector('#custom-youtube-style');
  53. if (style) style.remove();
  54. }
  55. }
  56.  
  57. function handleScroll() {
  58. const navbar = document.querySelector('#masthead-container');
  59. if (!navbar) return;
  60.  
  61. if (window.scrollY > 0) {
  62. navbar.style.opacity = '1';
  63. navbar.style.pointerEvents = 'auto';
  64. } else {
  65. navbar.style.opacity = '0';
  66. navbar.style.pointerEvents = 'none';
  67. }
  68. }
  69.  
  70. const observer = new MutationObserver(updateStyles);
  71. observer.observe(document.body, { childList: true, subtree: true });
  72.  
  73. window.addEventListener('scroll', handleScroll);
  74.  
  75. updateStyles();
  76. })();