Greasy Fork

Greasy Fork is available in English.

Hide YouTube Shorts Shelf in the video detailed page

Hides the YouTube Shorts shelf by setting display to none and height to zero

当前为 2024-12-24 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hide YouTube Shorts Shelf in the video detailed page
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Hides the YouTube Shorts shelf by setting display to none and height to zero
// @author       aspen138
// @match        *://www.youtube.com/*
// @grant        none
// @run-at       document-end
// @icon         https://www.youtube.com/favicon.ico
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide the Shorts shelf
    function hideShortsShelf() {
        // Select the Shorts shelf element
        const shortsShelf = document.querySelector('ytd-reel-shelf-renderer');

        if (shortsShelf) {
            // Apply styles to hide the element
            shortsShelf.style.setProperty('display', 'none', 'important');
            shortsShelf.style.setProperty('height', '0', 'important');
            console.log('YouTube Shorts shelf has been hidden.');
        }
    }

    // Initial attempt to hide the Shorts shelf
    hideShortsShelf();

    // Observe changes in the DOM to hide the Shorts shelf if it loads later
    const observer = new MutationObserver((mutations) => {
        for (let mutation of mutations) {
            if (mutation.addedNodes.length) {
                hideShortsShelf();
            }
        }
    });

    // Start observing the body for added nodes
    observer.observe(document.body, { childList: true, subtree: true });

})();