YouTube Performance Booster (Fixed UI)

Optimizes YouTube performance without breaking UI elements

当前为 2025-06-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Performance Booster (Fixed UI)
// @version      2.1
// @description  Optimizes YouTube performance without breaking UI elements
// @author       HYPERR.
// @match        *://*.youtube.com/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @run-at       document-start
// @license      MIT
// @namespace https://greasyfork.org/users/1476487
// ==/UserScript==

(function() {
    'use strict';
    
    // ===== SAFE CONFIGURATION =====
    const settings = {
        instantNavigation: true,      // Smoother navigation
        disableAnimations: true,      // Disable UI animations
        qualityPreset: 'auto',        // Video quality (auto, 1080p, 720p etc)
        hideShorts: true              // Only hides Shorts shelf
    };

    // ===== SAFE CSS INJECTION =====
    GM_addStyle(`
        /* Animation removal (safe) */
        [no-animations] * {
            transition: none !important;
            animation: none !important;
        }
        
        /* Non-destructive hiding */
        [hide-shorts] ytd-rich-section-renderer {
            display: none !important;
        }
        
        /* Layout-safe optimizations */
        html {
            scroll-behavior: auto !important;
        }
    `);

    // Apply settings
    document.documentElement.setAttribute('no-animations', '');
    if (settings.hideShorts) {
        document.documentElement.setAttribute('hide-shorts', '');
    }

    // ===== SAFE PERFORMANCE OPTIMIZATIONS =====
    function optimizePlayer() {
        const player = document.querySelector('video');
        if (player) {
            player.addEventListener('canplay', function() {
                try {
                    if (settings.qualityPreset !== 'auto') {
                        player.setPlaybackQuality(settings.qualityPreset);
                    }
                } catch(e) { /* Fail silently */ }
            });
        }
    }

    // ===== SAFE INSTANT NAVIGATION =====
    if (settings.instantNavigation) {
        document.addEventListener('mouseover', function(e) {
            const link = e.target.closest('a[href^="/watch"]');
            if (link) {
                const preload = document.createElement('link');
                preload.rel = 'prefetch';
                preload.href = link.href;
                document.head.appendChild(preload);
            }
        }, {passive: true});
    }

    // Initialize
    const observer = new MutationObserver(optimizePlayer);
    observer.observe(document, {
        childList: true,
        subtree: true
    });
    window.addEventListener('load', optimizePlayer);
})();