YouTube - Shorts remover

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();