YouTube - Shorts remover

Remove all short videos from your homepage, subscription feed, search and watch page on YouTube.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        YouTube - Shorts remover
// @namespace   https://greasyfork.org/en/users/2755-robotoilinc
// @author      RobotOilInc
// @version     0.6.0
// @license     MIT
// @description Remove all short videos from your homepage, subscription feed, search and watch page on YouTube.
// @match       https://*.youtube.com/
// @match       https://*.youtube.com/feed/*
// @match       https://*.youtube.com/results*
// @match       https://*.youtube.com/watch*
// @match       https://youtube.com/
// @match       https://youtube.com/feed/*
// @match       https://youtube.com/results*
// @match       https://youtube.com/watch*
// @icon        https://i.imgur.com/rvNc0hN.png
// @grant       none
// ==/UserScript==
const observer = new MutationObserver(function(mutationList, observer) {
    // Remove any reel shelves
    const shelves = document.getElementsByTagName('ytd-reel-shelf-renderer')
    for (let i = 0; i < shelves.length; i++) {
        console.log("Removing shorts shelf", shelves[i]);
        shelves[i].remove()
    }

    // Remove any rich reel shelves
    const richShelves = document.getElementsByTagName('ytd-rich-shelf-renderer')
    for (let i = 0; i < richShelves.length; i++) {
        console.log("Removing shorts shelf", richShelves[i]);
        richShelves[i].remove()
    }

    // Remove anything with the shorts overlay
    const overlays = document.querySelectorAll('ytd-thumbnail-overlay-time-status-renderer[overlay-style="SHORTS"]');
    for (let i = 0; i < overlays.length; i++) {
        const element = overlays[i];

        const section = element.closest('.ytd-item-section-renderer');
        if (section) { console.log("Removing short overlay", element); section.remove(); return; }

        const grid = element.closest('.ytd-grid-renderer');
        if (grid) { console.log("Removing short overlay", element); grid.remove(); return; }

        const list = element.closest('.ytd-section-list-renderer');
        if (list) { console.log("Removing short overlay", element); list.remove(); }
    }
});


const observeShorts = () => {
    observer.observe(document.querySelector('ytd-page-manager'), { childList: true, subtree: true });
}

// Ensure the observer is update when we navigate away
window.navigation.addEventListener("navigate", (event) => {
    observer.disconnect();
    observeShorts()
});

// Ensure we observe on initial load as well
observeShorts();