优酷全屏模式

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

当前为 2022-07-23 提交的版本,查看 最新版本

  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 2022.07.23.21.19
  18. // @author ndaesik
  19. // @icon https://lh3.googleusercontent.com/iLZyxGK7l1343U4E7eAfgKbRWW6qhzCJq-Z92M60JzCMntFyaFF2GUQVRxPhfGcy6qRISLjHv4fX1vtq0TZkZMAzBjM
  20. // @match *://*.youtube.com/*
  21. // ==/UserScript==
  22.  
  23. const suggestBoxToDarkCSS = document.createElement('style');
  24. suggestBoxToDarkCSS.innerText = `
  25. [dark] {color-scheme: dark;}
  26. [dark] .gstl_50.sbdd_a * {background-color:#121212; border-color:#303030;}
  27. [dark] .gsfs,[dark] .sbpqs_a {color:#FFF;}
  28. [dark] .sbqs_c:before {filter: invert(1);} `.replaceAll(';','!important;')
  29.  
  30. const fullscreenVideoCSS = document.createElement('style');
  31. fullscreenVideoCSS.innerText = `
  32. ytd-watch-flexy[theater] .ytp-chrome-top .ytp-button {padding-top: 68px;}
  33. ytd-app:not([guide-persistent-and-visible]) [theater] #player video,
  34. :is(ytd-watch-flexy[theater],ytd-watch-flexy[fullscreen]) #player-theater-container {
  35. height: 100vh; max-height: 100vh; min-height: 100vh;}`.replaceAll(';','!important;')
  36.  
  37. const autoHideTopCSS = document.createElement('style');
  38. autoHideTopCSS.innerText = `
  39. 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;}
  40. 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);}
  41. ytd-app:not([guide-persistent-and-visible]) ytd-page-manager {margin-top: 0;}`.replaceAll(';','!important;')
  42. autoHideTopCSS.className = "autoHideTopCSS";
  43.  
  44. function isWatchPage() {
  45. return !(document.URL.indexOf('watch') == -1)
  46. };
  47.  
  48. function isTheaterMode() {
  49. let scrollbarWidth = window.innerWidth - document.querySelector('ytd-app').offsetWidth;
  50. let playerWidth = document.querySelector('#ytd-player')?.offsetWidth;
  51. let isWidePlayer = scrollbarWidth + playerWidth == window.innerWidth;
  52. return ( isWatchPage() && isWidePlayer )
  53. };
  54.  
  55. function alwaysTheaterMode() {
  56. let clickModeButtonRepeatly = setInterval( _ => {
  57. if ( isTheaterMode() ) {
  58. clearInterval( clickModeButtonRepeatly );
  59. } else {
  60. document.querySelectorAll('.ytp-size-button')?.forEach( e => e.click());
  61. clearInterval( clickModeButtonRepeatly );
  62. }
  63. }, 100);
  64. setTimeout( _ => {
  65. clearInterval( clickModeButtonRepeatly );
  66. }, 10000);
  67. };
  68.  
  69. ['yt-navigate-finish', 'load', 'unload'].forEach( e => {
  70. window.addEventListener( e, _ => {
  71. isWatchPage() ? document.head.appendChild(autoHideTopCSS) : false;
  72. document.head.appendChild(suggestBoxToDarkCSS);
  73. document.head.appendChild(fullscreenVideoCSS);
  74. alwaysTheaterMode();
  75. window.scrollTo(0, 0);
  76. });
  77. });
  78.  
  79. window.addEventListener('click', _ => {
  80. setTimeout( _ => {
  81. if ( !isWatchPage() || !isTheaterMode() ) {
  82. document.querySelector('.autoHideTopCSS')?.remove()
  83. } else if ( isTheaterMode() ) {
  84. document.head.appendChild(autoHideTopCSS)
  85. }
  86. }, 100);
  87. });