Hide YouTube Shorts

Hides YouTube Shorts videos from showing across the YouTube website.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Hide YouTube Shorts
// @namespace    https://www.taylrr.co.uk/
// @version      0.3
// @description  Hides YouTube Shorts videos from showing across the YouTube website.
// @author       taylor8294
// @match        https://www.youtube.com/
// @match        https://www.youtube.com/feed/subscriptions*
// @match        https://www.youtube.com/feed/explore*
// @match        https://www.youtube.com/feed/trending*
// @match        https://www.youtube.com/results*
// @match        https://www.youtube.com/watch*
// @match        https://www.youtube.com/shorts*
// @icon         https://i.ytimg.com/an/r0deIusKuMOsUobj89aPZA/featured_channel.jpg?v=60f4dc70
// @grant        none
// @license      GPLv3
// @require      https://cdn.jsdelivr.net/npm/[email protected]/minified/arrive.min.js
// ==/UserScript==

(function() {
    'use strict';

    if(window.location.pathname.toLowerCase().startsWith('/shorts/')){
        window.location.href = window.location.origin+'/watch?v='+window.location.pathname.replace(/^\/shorts\//g,'')+window.location.search.replace(/^\?/g,'&')
    } else {
        let removeShorts = function(){
            // Explore and Trending
            Array.from(document.querySelectorAll('h2.ytd-reel-shelf-renderer')).filter(h2 => h2.textContent.includes('Shorts')).forEach(h2 => {
                if(h2.closest('ytd-reel-shelf-renderer')){
                    h2.closest('ytd-reel-shelf-renderer').remove()
                } else h2.closest('ytd-item-section-renderer')?.remove()
            })
            Array.from(document.querySelectorAll('a.ytd-thumbnail[href^="/shorts"]')).forEach(a => a.closest('ytd-video-renderer')?.remove() )
            Array.from(document.querySelectorAll('#video-title.ytd-video-renderer')).forEach(a => /\#shorts?/.test(a.innerText.toLowerCase()) ? a.closest('ytd-video-renderer')?.remove() : null)
            Array.from(document.querySelectorAll('#description-text.ytd-video-renderer')).forEach(yfs => /\#shorts?/.test(yfs.innerText.toLowerCase()) ? yfs.closest('ytd-video-renderer')?.remove() : null )

            // Search
            Array.from(document.querySelectorAll('.title-and-badge.ytd-video-renderer')).forEach(h3 => /\#shorts?/.test(h3.innerText.toLowerCase()) ? h3.closest('ytd-video-renderer')?.remove() : null)
            Array.from(document.querySelectorAll('.metadata-snippet-container.ytd-video-renderer')).forEach(div => /\#shorts?/.test(div.innerText.toLowerCase()) ? div.closest('ytd-video-renderer')?.remove() : null)

            // Recommended
            Array.from(document.querySelectorAll('#video-title.ytd-compact-video-renderer')).forEach(span => /\#shorts?/.test(span.innerText.toLowerCase()) ? span.closest('ytd-compact-video-renderer')?.remove() : null)

            // Subscriptions and Home
            Array.from(document.querySelectorAll('h2.ytd-rich-shelf-renderer')).filter(h2 => h2.textContent.includes('Shorts')).forEach(h2 => h2.closest('ytd-rich-section-renderer')?.remove())

            // Side menu
            Array.from(document.querySelectorAll('ytd-guide-entry-renderer')).filter(el => el.textContent.includes('Shorts')).forEach(el => el?.remove())
        }

        document.arrive('ytd-reel-shelf-renderer, ytd-item-section-renderer, ytd-video-renderer, ytd-compact-video-renderer, ytd-rich-section-renderer, ytd-guide-entry-renderer', function () {
            removeShorts();
            console.log("[removeShorts called]");
        });

        removeShorts()
    }
})();