Remove Youtube Shorts

Remove youtube shorts junk

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Remove Youtube Shorts
// @namespace    https://www.youtube.com/
// @version      0.2
// @description  Remove youtube shorts junk
// @author       Scamcast
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function RemoveShorts() {
        document.querySelectorAll('ytd-grid-video-renderer').forEach(video => {
            try {
                if (video.__data.data.navigationEndpoint.commandMetadata.webCommandMetadata.webPageType.match(/shorts/i)) video.remove();
            } catch (e) {}
        });

        document.querySelectorAll('ytd-guide-entry-renderer.ytd-guide-section-renderer').forEach(guideItem => {
            try {
                if (guideItem.__data.data.formattedTitle.simpleText.match(/shorts/i)) guideItem.remove();
            } catch (e) {}
        });

        document.querySelectorAll('tp-yt-paper-tab').forEach(tab => {
            try {
                if (tab.textContent.match(/shorts/i)) tab.remove();
            } catch (e) {}
        });
        document.querySelectorAll('ytd-reel-shelf-renderer, ytd-rich-shelf-renderer').forEach(reelshelf => reelshelf.remove());
    }

    RemoveShorts();
    let JunkCheckInterval = setInterval(RemoveShorts, 1000);

    window.addEventListener('focus', (e)=>{
        if (document.hasFocus() && document.visibilityState == 'visible'){
            clearInterval(JunkCheckInterval);
            JunkCheckInterval = setInterval(RemoveShorts, 1000);
        } else if (!document.hasFocus() || document.visibilityState == 'hidden') {
            clearInterval(JunkCheckInterval);
        };
    });
    window.addEventListener('visibilitychange', (e)=>{
        if (!document.hasFocus() || document.visibilityState == 'hidden') {
            clearInterval(JunkCheckInterval);
        };
    })
})();