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 提交的版本。查看 最新版本

// ==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 });

})();