YouTube Unshortened

Hides YouTube Shorts shelves and videos on Home, Subscriptions, and Channel pages.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Unshortened
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Hides YouTube Shorts shelves and videos on Home, Subscriptions, and Channel pages.
// @author       OthorWight
// @match        *://www.youtube.com/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const hideShortsElements = () => {

        // Hide the entire "Shorts" shelf.
        // YouTube uses a specific attribute `is-shorts` for the shelf renderer.
        document.querySelectorAll('ytd-rich-shelf-renderer[is-shorts]')
            .forEach(shelf => {
                // We hide the entire parent "section" to remove the title and spacing.
                const section = shelf.closest('ytd-rich-section-renderer');
                if (section && section.style.display !== 'none') {
                    section.style.display = 'none';
                }
            });

        // Hide individual Short videos that may appear in regular feeds.
        // We can identify these by the "/shorts/" in their URL.
        // We cover multiple types of video renderers for broad compatibility.
        const individualShortSelectors = [
            'ytd-grid-video-renderer:has(a[href^="/shorts/"])', // Grid view (e.g., Subscriptions)
            'ytd-rich-item-renderer:has(a[href^="/shorts/"])', // Home page rich grid
            'ytd-video-renderer:has(a[href^="/shorts/"])', // List view (e.g., Search results)
            'ytd-reel-item-renderer' // Renderer specifically for Shorts reels
        ];

        document.querySelectorAll(individualShortSelectors.join(','))
            .forEach(video => {
                if (video.style.display !== 'none') {
                    video.style.display = 'none';
                }
            });
    };

    // YouTube loads content dynamically. A MutationObserver is the most
    // reliable way to act on new elements as they are added to the page.
    const observer = new MutationObserver(hideShortsElements);

    // Start observing the entire document for changes to the list of elements.
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    // Run the function once when the script is first injected,
    // just in case some elements are already on the page.
    hideShortsElements();
})();