优酷全屏模式

YouTube画面自动转换成100高、100宽的画面。

  1. // ==UserScript==
  2. // @name:ko 유튜브 풀스크린
  3. // @name Youtube Fullscreen Mode
  4. // @name:ru Youtube Полный режим
  5. // @name:ja Youtubeフルスクリーンモードの
  6. // @name:zh-CN 优酷全屏模式
  7. // @name:zh-TW 優酷全屏模式
  8.  
  9. // @description:ko 유튜브 화면을 자동으로 꽉 찬 화면으로 바꿉니다.
  10. // @description Automatically switch YouTube screens to 100 height and 100 width screens.
  11. // @description:ru Автоматическое переключение экрана на YouTube на экран высотой 100 и шириной 100.
  12. // @description:ja ユーチューブ画面を高さ100、広さ100画面に自動転換。
  13. // @description:zh-CN YouTube画面自动转换成100高、100宽的画面。
  14. // @description:zh-TW YouTube畫面自動轉換成100高、100寬的畫面。
  15.  
  16. // @namespace https://ndaesik.tistory.com/
  17. // @version 2025.01.01.1000
  18. // @author ndaesik
  19. // @icon https://lh3.googleusercontent.com/iLZyxGK7l1343U4E7eAfgKbRWW6qhzCJq-Z92M60JzCMntFyaFF2GUQVRxPhfGcy6qRISLjHv4fX1vtq0TZkZMAzBjM
  20. // @match *://*.youtube.com/*
  21. // @grant window.focus
  22. // ==/UserScript==
  23.  
  24. const suggestBoxToDarkCSS = document.createElement('style');
  25. suggestBoxToDarkCSS.innerText = `
  26. body{overflow-y:auto;}
  27. [dark] {color-scheme: dark;}`.replaceAll(';','!important;')
  28.  
  29. const fullscreenVideoCSS = document.createElement('style');
  30. fullscreenVideoCSS.innerText = `
  31. ytd-app:not([guide-persistent-and-visible]) [theater] #player video,
  32. :is(ytd-watch-flexy[theater],ytd-watch-flexy[fullscreen]) #full-bleed-container {
  33. height: 100vh; max-height: 100vh; min-height: 100vh;}
  34. ytd-watch-flexy[theater] {scrollbar-width: none;}
  35. ytd-watch-flexy[theater]::-webkit-scrollbar {display: none;}
  36. ytd-watch-flexy[theater] ~ body {scrollbar-width: none;-ms-overflow-style: none;}
  37. ytd-watch-flexy[theater] ~ body::-webkit-scrollbar {display: none;}`.replaceAll(';','!important;')
  38.  
  39. const autoHideTopCSS = document.createElement('style');
  40. autoHideTopCSS.innerText = `
  41. #masthead-container.ytd-app:hover, #masthead-container.ytd-app:focus-within {width:100%;}
  42. #masthead-container.ytd-app,
  43. #masthead-container.ytd-app:not(:hover):not(:focus-within) {width:calc(50% - 150px);}
  44. #masthead-container.ytd-app:not(:hover):not(:focus-within) {transition:width 0.4s ease-out 0.4s;}
  45. ytd-app:not([guide-persistent-and-visible]) :is(#masthead-container ytd-masthead, #masthead-container.ytd-app::after) {transform: translateY(-56px); transition: transform .1s .3s ease-out;}
  46. ytd-app:not([guide-persistent-and-visible]) :is(#masthead-container:hover ytd-masthead, #masthead-container:hover.ytd-app::after, #masthead-container:focus-within ytd-masthead) {transform: translateY(0px);}
  47. ytd-app:not([guide-persistent-and-visible]) ytd-page-manager {margin-top: 0;}`.replaceAll(';','!important;')
  48. autoHideTopCSS.className = "autoHideTopCSS";
  49.  
  50. const $ = {
  51. elements: { ytdApp: null, player: null, chatFrame: null },
  52. update() {
  53. this.elements.ytdApp = document.querySelector('ytd-app');
  54. this.elements.player = document.querySelector('#ytd-player');
  55. this.elements.chatFrame = document.querySelector('ytd-live-chat-frame');
  56. }
  57. };
  58.  
  59. let scrollTimer = null, isContentHidden = false;
  60.  
  61. const isWatchPage = () => document.URL.includes('/watch?');
  62.  
  63. const isTheaterMode = () => {
  64. $.update();
  65. const { ytdApp, player, chatFrame } = $.elements;
  66. return ytdApp && player && isWatchPage() &&
  67. (window.innerWidth - ytdApp.offsetWidth + player.offsetWidth +
  68. (chatFrame && !chatFrame.attributes.collapsed ? chatFrame.offsetWidth : 0)) === window.innerWidth;
  69. };
  70.  
  71. const shouldShowAutoHideCSS = () => {
  72. const scrollPosition = window.scrollY;
  73. const viewportHeight = window.innerHeight + 56;
  74. return isWatchPage() && isTheaterMode() && scrollPosition <= viewportHeight;
  75. };
  76.  
  77. const updateAutoHideCSS = () => {
  78. const existingCSS = document.querySelector('.autoHideTopCSS');
  79. shouldShowAutoHideCSS() ? !existingCSS && document.head.appendChild(autoHideTopCSS) : existingCSS?.remove();
  80. };
  81.  
  82. const checkConditions = () => {
  83. const watchFlexy = document.querySelector('ytd-watch-flexy');
  84. const primaryContent = document.querySelector('#primary');
  85. const secondaryContent = document.querySelector('#secondary');
  86. const isTheater = watchFlexy?.hasAttribute('theater');
  87. const isScrollTop = window.scrollY === 0;
  88.  
  89. if (!primaryContent || !secondaryContent || !isTheater) return;
  90.  
  91. if (isScrollTop && !isContentHidden) {
  92. if (scrollTimer) clearTimeout(scrollTimer);
  93. scrollTimer = setTimeout(() => {
  94. primaryContent.style.display = 'none';
  95. secondaryContent.style.display = 'none';
  96. isContentHidden = true;
  97. }, 2000);
  98. } else if (!isScrollTop && scrollTimer) {
  99. clearTimeout(scrollTimer);
  100. scrollTimer = null;
  101. isContentHidden && (primaryContent.style.display = '', secondaryContent.style.display = '', isContentHidden = false);
  102. }
  103. };
  104.  
  105. const showContent = () => {
  106. const primaryContent = document.querySelector('#primary');
  107. const secondaryContent = document.querySelector('#secondary');
  108. if (isContentHidden && primaryContent && secondaryContent) {
  109. primaryContent.style.display = '';
  110. secondaryContent.style.display = '';
  111. isContentHidden = false;
  112. scrollTimer && (clearTimeout(scrollTimer), scrollTimer = null);
  113. setTimeout(() => checkConditions(), 1000);
  114. }
  115. };
  116.  
  117. const alwaysTheaterMode = () => {
  118. const interval = setInterval(() => isTheaterMode() ? clearInterval(interval) :
  119. document.querySelectorAll('.ytp-size-button')?.forEach(e => e.click()), 100);
  120. setTimeout(() => clearInterval(interval), 10000);
  121. };
  122.  
  123.  
  124. const setupEventListeners = () => {
  125. window.addEventListener('scroll', () => requestAnimationFrame(checkConditions));
  126. document.addEventListener('click', () => requestAnimationFrame(showContent));
  127. document.addEventListener('wheel', () => requestAnimationFrame(showContent));
  128. const observer = new MutationObserver(() => requestAnimationFrame(checkConditions));
  129. const watchFlexy = document.querySelector('ytd-watch-flexy');
  130. watchFlexy && observer.observe(watchFlexy, { attributes: true, attributeFilter: ['theater'] });
  131. };
  132.  
  133. let previousUrl = window.location.href;
  134. window.addEventListener('yt-navigate-start', () => {
  135. const currentUrl = window.location.href;
  136. currentUrl !== previousUrl && !previousUrl.includes('/watch') && currentUrl.includes('/watch') && window.location.reload();
  137. previousUrl = currentUrl;
  138. });
  139.  
  140. ['yt-navigate-finish', 'load', 'unload', 'locationchange'].forEach(event =>
  141. window.addEventListener(event, () => {
  142. document.head.appendChild(suggestBoxToDarkCSS);
  143. document.head.appendChild(fullscreenVideoCSS);
  144. alwaysTheaterMode();
  145. window.scrollTo(0, 0);
  146. updateAutoHideCSS();
  147. setupEventListeners();
  148. checkConditions();
  149. }));
  150.  
  151. window.addEventListener('click', () => setTimeout(updateAutoHideCSS, 100));
  152. window.addEventListener('scroll', () => requestAnimationFrame(updateAutoHideCSS));

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址