YouTube Ultra Optimizer Pro

Aggressively optimize YouTube for slow connections and weak PCs, bypass restrictions

  1. // ==UserScript==
  2. // @name YouTube Ultra Optimizer Pro
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Aggressively optimize YouTube for slow connections and weak PCs, bypass restrictions
  6. // @match https://www.youtube.com/*
  7. // @grant GM_addStyle
  8. // @run-at document-start
  9. // @author https://t.me/aisingers
  10. // @source https://t.me/aisingers
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Функция для перехвата и модификации запросов
  18. function interceptRequests() {
  19. const originalFetch = window.fetch;
  20. window.fetch = async function(...args) {
  21. const url = args[0];
  22. if (typeof url === 'string') {
  23. if (url.includes('videoplayback') || url.includes('youtubei/v1/player')) {
  24. args[0] = url + (url.includes('?') ? '&' : '?') + 'nocache=' + Math.random() + '&ultraoptimizer=1';
  25. if (!args[1]) args[1] = {};
  26. if (!args[1].headers) args[1].headers = {};
  27. args[1].headers['X-Forwarded-For'] = '8.8.8.8';
  28. args[1].headers.Origin = 'https://www.youtube.com';
  29. args[1].headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36';
  30. }
  31. if (url.includes('yt3.ggpht.com')) {
  32. args[0] = url.replace('yt3.ggpht.com', 'i.ytimg.com');
  33. }
  34. }
  35. return originalFetch.apply(this, args);
  36. };
  37.  
  38. const originalXHR = window.XMLHttpRequest;
  39. window.XMLHttpRequest = function() {
  40. const xhr = new originalXHR();
  41. const originalOpen = xhr.open;
  42. xhr.open = function(...args) {
  43. const url = args[1];
  44. if (typeof url === 'string' && (url.includes('videoplayback') || url.includes('youtubei/v1/player'))) {
  45. args[1] = url + (url.includes('?') ? '&' : '?') + 'nocache=' + Math.random() + '&ultraoptimizer=1';
  46. }
  47. return originalOpen.apply(xhr, args);
  48. };
  49. return xhr;
  50. };
  51. }
  52.  
  53. // Функция для оптимизации плеера
  54. function optimizePlayer() {
  55. const script = document.createElement('script');
  56. script.textContent = `
  57. if (window.ytplayer && window.ytplayer.config) {
  58. Object.assign(window.ytplayer.config.args, {
  59. adaptive_fmts: '',
  60. progressive: '1',
  61. dash: '0',
  62. live_chunk_readahead: '3',
  63. disable_html5_preload: 'false',
  64. html5_prefer_low_quality: 'false',
  65. el: 'embedded',
  66. autoplay: '0',
  67. delay_load_comments: '1',
  68. vss_host: 'www.youtube.com',
  69. force_speedsub_tlae: '',
  70. force_adbreak_through_yt: 'true'
  71. });
  72. }
  73. `;
  74. document.head.appendChild(script);
  75. }
  76.  
  77. // Функция для оптимизации перемотки
  78. function optimizeSeeking() {
  79. document.addEventListener('seeking', function(e) {
  80. if (e.target.tagName === 'VIDEO') {
  81. const currentQuality = e.target.getPlaybackQuality();
  82. e.target.setPlaybackQuality('tiny');
  83. e.target.playbackRate = 0.25;
  84. setTimeout(() => {
  85. e.target.setPlaybackQuality(currentQuality);
  86. e.target.playbackRate = 1;
  87. }, 3000);
  88. }
  89. }, true);
  90. }
  91.  
  92. // Функция для оптимизации загрузки комментариев
  93. function optimizeComments() {
  94. const observer = new MutationObserver((mutations) => {
  95. mutations.forEach((mutation) => {
  96. if (mutation.addedNodes.length) {
  97. mutation.addedNodes.forEach(node => {
  98. if (node.nodeType === 1 && node.tagName === 'YTD-COMMENT-THREAD-RENDERER') {
  99. node.style.opacity = '0.8';
  100. node.style.transition = 'opacity 0.3s ease';
  101. node.addEventListener('mouseover', () => node.style.opacity = '1');
  102. node.addEventListener('mouseout', () => node.style.opacity = '0.8');
  103. }
  104. });
  105. }
  106. });
  107. });
  108.  
  109. observer.observe(document.body, { childList: true, subtree: true });
  110. }
  111.  
  112. // Функция для добавления индикатора работы скрипта
  113. function addScriptIndicator() {
  114. const indicator = document.createElement('div');
  115. indicator.id = 'script-indicator';
  116. indicator.textContent = 'Ultra Optimizer Pro v1.0';
  117. indicator.style.cssText = `
  118. position: fixed;
  119. bottom: 10px;
  120. right: 10px;
  121. background-color: green;
  122. color: white;
  123. padding: 5px 10px;
  124. border-radius: 5px;
  125. z-index: 9999;
  126. opacity: 0.7;
  127. font-size: 12px;
  128. `;
  129. document.body.appendChild(indicator);
  130. }
  131.  
  132. // Основная функция
  133. function main() {
  134. interceptRequests();
  135. optimizePlayer();
  136. optimizeSeeking();
  137. optimizeComments();
  138. addScriptIndicator();
  139. }
  140.  
  141. // Запуск скрипта при загрузке страницы
  142. if (document.readyState === 'loading') {
  143. document.addEventListener('DOMContentLoaded', main);
  144. } else {
  145. main();
  146. }
  147.  
  148. // Добавление стилей для оптимизации
  149. GM_addStyle(`
  150. body {
  151. font-family: Arial, sans-serif !important;
  152. }
  153. ytd-watch-flexy[flexy][is-two-columns_] #secondary.ytd-watch-flexy {
  154. opacity: 0.8;
  155. transition: opacity 0.3s ease;
  156. }
  157. ytd-watch-flexy[flexy][is-two-columns_] #secondary.ytd-watch-flexy:hover {
  158. opacity: 1;
  159. }
  160. .ytp-chrome-top, .ytp-chrome-bottom {
  161. opacity: 0.5 !important;
  162. transition: opacity 0.3s ease;
  163. }
  164. .ytp-chrome-top:hover, .ytp-chrome-bottom:hover {
  165. opacity: 1 !important;
  166. }
  167. .ytp-gradient-top, .ytp-gradient-bottom {
  168. display: none !important;
  169. }
  170. * {
  171. transition: none !important;
  172. animation: none !important;
  173. }
  174. #masthead-container {
  175. opacity: 0.8;
  176. transition: opacity 0.3s ease;
  177. }
  178. #masthead-container:hover {
  179. opacity: 1;
  180. }
  181. .ytd-thumbnail {
  182. filter: grayscale(30%);
  183. transition: filter 0.3s ease;
  184. }
  185. .ytd-thumbnail:hover {
  186. filter: grayscale(0%);
  187. }
  188. ytd-video-renderer, ytd-compact-video-renderer {
  189. margin-bottom: 10px !important;
  190. }
  191. #content.ytd-app {
  192. margin-top: 56px !important;
  193. }
  194. .html5-video-player {
  195. max-width: 100% !important;
  196. }
  197. .ytp-spinner {
  198. display: none !important;
  199. }
  200. ytd-watch-flexy[flexy][is-two-columns_] #primary.ytd-watch-flexy {
  201. max-width: 100% !important;
  202. }
  203. ytd-watch-flexy[flexy][is-two-columns_] #secondary.ytd-watch-flexy {
  204. padding-left: 10px !important;
  205. }
  206. yt-img-shadow {
  207. background-color: transparent !important;
  208. }
  209. `);
  210.  
  211. // Дополнительная функция для оптимизации загрузки видео
  212. function optimizeVideoLoading() {
  213. const observer = new IntersectionObserver((entries) => {
  214. entries.forEach(entry => {
  215. if (entry.isIntersecting) {
  216. const video = entry.target.querySelector('video');
  217. if (video) {
  218. video.play().catch(() => {});
  219. }
  220. } else {
  221. const video = entry.target.querySelector('video');
  222. if (video) {
  223. video.pause();
  224. }
  225. }
  226. });
  227. }, { threshold: 0.5 });
  228.  
  229. document.querySelectorAll('ytd-player').forEach(player => {
  230. observer.observe(player);
  231. });
  232. }
  233.  
  234. // Добавляем новую функцию в основную функцию
  235. function main() {
  236. interceptRequests();
  237. optimizePlayer();
  238. optimizeSeeking();
  239. optimizeComments();
  240. optimizeVideoLoading();
  241. addScriptIndicator();
  242. }
  243.  
  244. // Функция для обхода ограничений скорости
  245. function bypassSpeedLimits() {
  246. const originalGetVideoPlaybackQuality = HTMLVideoElement.prototype.getVideoPlaybackQuality;
  247. HTMLVideoElement.prototype.getVideoPlaybackQuality = function() {
  248. const result = originalGetVideoPlaybackQuality.call(this);
  249. result.totalVideoFrames *= 0.75;
  250. result.droppedVideoFrames = 0;
  251. return result;
  252. };
  253. }
  254.  
  255. // Обновляем существующую функцию main
  256. main = function() {
  257. interceptRequests();
  258. optimizePlayer();
  259. optimizeSeeking();
  260. optimizeComments();
  261. optimizeVideoLoading();
  262. bypassSpeedLimits();
  263. addScriptIndicator();
  264. };
  265.  
  266. })();

QingJ © 2025

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