YouTube transparent

Прозрачность комментариев и другой информации

目前為 2025-03-30 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @license MIT
  3. // @name YouTube transparent
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1_alpha
  6. // @description Прозрачность комментариев и другой информации
  7. // @match https://www.youtube.com/*
  8. // @grant GM_addStyle
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const CSS = `
  16. /* Основные стили */
  17. ytd-watch-flexy {
  18. max-width: 100% !important;
  19. padding: 0 !important;
  20. }
  21.  
  22. #secondary {
  23. display: inline !important;
  24. z-index: 4;
  25. margin-top: calc(25vh - 145px) !important;
  26. }
  27.  
  28. /* Видео-контейнер */
  29. #movie_player.ultrawide-active {
  30. position: fixed !important;
  31. left: 0 !important;
  32. width: 100% !important;
  33. height: calc(100vh - 60px) !important;
  34. z-index: 1 !important;
  35. }
  36.  
  37. /* Затемнение и контент */
  38. .ultrawide-overlay {
  39. position: fixed;
  40. top: 0;
  41. left: 0;
  42. width: 100%;
  43. height: 100vh;
  44. background: rgba(0,0,0,0);
  45.  
  46. backdrop-filter: blur(0px); /* Добавлено размытие */
  47.  
  48. z-index: 2;
  49. pointer-events: none;
  50. transition: background 0.3s ease;
  51. }
  52.  
  53. .ultrawide-content-container {
  54. position: relative !important;
  55. z-index: 3 !important;
  56. padding: 5px 5% 5px 5% !important;
  57. margin-top: calc(25vh - 160px) !important;
  58. background: transparent !important;
  59. max-height: 60vh !important;
  60. overflow-y: none !important;
  61. box-sizing: border-box !important;
  62. }
  63.  
  64. /* Оптимизация заголовка */
  65. #title.ytd-watch-metadata {
  66. margin: 15px 0 !important;
  67. }
  68.  
  69. /* Адаптация для мобильных */
  70. @media (max-width: 600px) {
  71. .ultrawide-content-container {
  72. padding: 10px !important;
  73. margin-top: 70vh !important;
  74. }
  75. }
  76. `;
  77.  
  78. let overlay = null;
  79. let scrollHandler = null;
  80.  
  81. const isVideoPage = () => {
  82. return window.location.pathname.includes('/watch');
  83. };
  84.  
  85. const init = () => {
  86. if (!isVideoPage()) {
  87. cleanup();
  88. return;
  89. }
  90.  
  91. const player = document.getElementById('movie_player');
  92. if (!player) return;
  93.  
  94. if (!overlay) {
  95. overlay = document.createElement('div');
  96. overlay.className = 'ultrawide-overlay';
  97. document.body.prepend(overlay);
  98. }
  99.  
  100. player.classList.add('ultrawide-active');
  101. const contentContainer = document.querySelector('#primary-inner');
  102. if (contentContainer) {
  103. contentContainer.classList.add('ultrawide-content-container');
  104. }
  105.  
  106. const updateLayout = () => {
  107. const playerHeight = player.offsetHeight;
  108. if (contentContainer) {
  109. contentContainer.style.marginTop = `${playerHeight * 0.85}px`;
  110. }
  111. };
  112.  
  113. scrollHandler = () => {
  114. const scrollY = window.scrollY;
  115. const playerHeight = player.offsetHeight;
  116. const opacity = Math.min(scrollY / (playerHeight * 0.5), 0.7);
  117. const bluramount = (Math.min(scrollY / (playerHeight * 0.5), 0.7)*3);
  118. overlay.style.background = `rgba(0,0,0,${opacity})`;
  119. overlay.style.backdropFilter = `blur(${bluramount}px)`;
  120. updateLayout();
  121. };
  122.  
  123. window.addEventListener('scroll', scrollHandler);
  124. updateLayout();
  125. };
  126.  
  127. const cleanup = () => {
  128. if (overlay) {
  129. overlay.remove();
  130. overlay = null;
  131. }
  132. if (scrollHandler) {
  133. window.removeEventListener('scroll', scrollHandler);
  134. scrollHandler = null;
  135. }
  136. document.querySelector('#movie_player')?.classList.remove('ultrawide-active');
  137. document.querySelector('#primary-inner')?.classList.remove('ultrawide-content-container');
  138. };
  139.  
  140. GM_addStyle(CSS);
  141.  
  142. new MutationObserver((mutations) => {
  143. if (!isVideoPage()) {
  144. cleanup();
  145. return;
  146. }
  147. const player = document.getElementById('movie_player');
  148. if (player && !player.classList.contains('ultrawide-active')) {
  149. cleanup();
  150. setTimeout(init, 300);
  151.  
  152. }
  153. }).observe(document.documentElement, {
  154. childList: true,
  155. subtree: true
  156. });
  157.  
  158. window.addEventListener('yt-navigate-finish', () => {
  159. if (isVideoPage()) {
  160. setTimeout(init, 500);
  161. } else {
  162. cleanup();
  163. }
  164. });
  165.  
  166. window.addEventListener('beforeunload', cleanup);
  167. })();

QingJ © 2025

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