LiteTube

Hide video recommendations from listing and remove annoying auto-mix playlists to reduce lag and improve performance

当前为 2025-11-08 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         LiteTube
// @namespace    http://tampermonkey.net/
// @version      v1.2
// @description  Hide video recommendations from listing and remove annoying auto-mix playlists to reduce lag and improve performance
// @author       Liminality Dreams
// @match        https://www.youtube.com/*
// @icon         https://img.icons8.com/?size=100&id=62852&format=png&color=228BE6
// @grant        none
// @run-at       document-start
// @license GNU 3.0
// ==/UserScript==

(function() {
    'use strict';

    let hasReloaded = false;

    function isAutoMix(listId) {
        if (!listId) return false;
        return listId.startsWith('RD') && !listId.startsWith('RDMM') && !listId.startsWith('RDAO') && !listId.startsWith('RDCLAK') && !listId.startsWith('RDTM') && !listId.startsWith('RDEM') && !listId.startsWith('RDPN');
    }

    function isWatchPage() {
        return window.location.pathname === '/watch';
    }

    function checkAndReload() {
        if (!isWatchPage() || hasReloaded) return;

        const url = new URL(window.location.href);
        const listParam = url.searchParams.get('list');

        if (listParam && isAutoMix(listParam)) {
            hasReloaded = true;
            url.searchParams.delete('list');
            url.searchParams.delete('start_radio');
            url.searchParams.delete('index');
            window.location.replace(url.toString());
        }
    }

    function removeWatchPageSidebar() {
        if (!isWatchPage()) return;
        document.querySelectorAll('#secondary').forEach(el => el.remove());
        document.querySelectorAll('ytd-watch-next-secondary-results-renderer').forEach(el => el.remove());
    }

    function removeBloat() {
        const bloatSelectors = [
            'ytd-rich-shelf-renderer[is-gaming]',
            'ytd-statement-banner-renderer',
            'ytd-banner-promo-renderer',
            'ytd-compact-promoted-video-renderer',
            'ytd-display-ad-renderer',
            'ytd-promoted-sparkles-web-renderer'
        ];
        bloatSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(el => el.remove());
        });
    }

    const style = document.createElement('style');
    style.textContent = `
        body[is-watch-page] #secondary,
        body[is-watch-page] ytd-watch-next-secondary-results-renderer,
        ytd-playlist-panel-renderer,
        .ytp-playlist-menu {
            display: none !important;
        }
    `;
    document.head.appendChild(style);

    checkAndReload();

    const observer = new MutationObserver(() => {
        if (isWatchPage()) {
            removeWatchPageSidebar();
        }
        removeBloat();
    });

    const startObserver = () => {
        if (document.body) {
            observer.observe(document.body, {
                subtree: true,
                childList: true
            });
        }
    };

    if (document.body) {
        startObserver();
    } else {
        document.addEventListener('DOMContentLoaded', startObserver);
    }

    window.addEventListener('yt-navigate-finish', () => {
        hasReloaded = false;
        checkAndReload();
        if (isWatchPage()) {
            setTimeout(removeWatchPageSidebar, 100);
        }
    });

})();