Greasy Fork 还支持 简体中文。

YouTube Performance Booster (Fixed UI)

Optimizes YouTube performance without breaking UI elements

  1. // ==UserScript==
  2. // @name YouTube Performance Booster (Fixed UI)
  3. // @version 2.1
  4. // @description Optimizes YouTube performance without breaking UI elements
  5. // @author HYPERR.
  6. // @match *://*.youtube.com/*
  7. // @grant GM_addStyle
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @run-at document-start
  11. // @license MIT
  12. // @namespace https://greasyfork.org/users/1476487
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. // ===== SAFE CONFIGURATION =====
  18. const settings = {
  19. instantNavigation: true, // Smoother navigation
  20. disableAnimations: true, // Disable UI animations
  21. qualityPreset: 'auto', // Video quality (auto, 1080p, 720p etc)
  22. hideShorts: true // Only hides Shorts shelf
  23. };
  24.  
  25. // ===== SAFE CSS INJECTION =====
  26. GM_addStyle(`
  27. /* Animation removal (safe) */
  28. [no-animations] * {
  29. transition: none !important;
  30. animation: none !important;
  31. }
  32. /* Non-destructive hiding */
  33. [hide-shorts] ytd-rich-section-renderer {
  34. display: none !important;
  35. }
  36. /* Layout-safe optimizations */
  37. html {
  38. scroll-behavior: auto !important;
  39. }
  40. `);
  41.  
  42. // Apply settings
  43. document.documentElement.setAttribute('no-animations', '');
  44. if (settings.hideShorts) {
  45. document.documentElement.setAttribute('hide-shorts', '');
  46. }
  47.  
  48. // ===== SAFE PERFORMANCE OPTIMIZATIONS =====
  49. function optimizePlayer() {
  50. const player = document.querySelector('video');
  51. if (player) {
  52. player.addEventListener('canplay', function() {
  53. try {
  54. if (settings.qualityPreset !== 'auto') {
  55. player.setPlaybackQuality(settings.qualityPreset);
  56. }
  57. } catch(e) { /* Fail silently */ }
  58. });
  59. }
  60. }
  61.  
  62. // ===== SAFE INSTANT NAVIGATION =====
  63. if (settings.instantNavigation) {
  64. document.addEventListener('mouseover', function(e) {
  65. const link = e.target.closest('a[href^="/watch"]');
  66. if (link) {
  67. const preload = document.createElement('link');
  68. preload.rel = 'prefetch';
  69. preload.href = link.href;
  70. document.head.appendChild(preload);
  71. }
  72. }, {passive: true});
  73. }
  74.  
  75. // Initialize
  76. const observer = new MutationObserver(optimizePlayer);
  77. observer.observe(document, {
  78. childList: true,
  79. subtree: true
  80. });
  81. window.addEventListener('load', optimizePlayer);
  82. })();