Hide YouTube Shorts

Hides YouTube Shorts videos from showing in Trending, Search and Recommended on the YouTube website.

目前为 2022-02-16 提交的版本。查看 最新版本

// ==UserScript==
// @name         Hide YouTube Shorts
// @namespace    https://www.taylrr.co.uk/
// @version      0.2
// @description  Hides YouTube Shorts videos from showing in Trending, Search and Recommended on the YouTube website.
// @author       taylor8294
// @include      https://www.youtube.com/feed/explore*
// @include      https://www.youtube.com/feed/trending*
// @include      https://www.youtube.com/results*
// @include      https://www.youtube.com/watch*
// @include      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('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)
        }

        document.arrive('ytd-video-renderer,ytd-compact-video-renderer', function () {
            removeShorts();
            console.log("[removeShorts called]")
        });

        removeShorts()
    }
})();