Remove YouTube Shorts

on the Subscription page. Desktop & Mobile.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name     	    Remove YouTube Shorts
// @description	    on the Subscription page. Desktop & Mobile.
// @version  	    1.8
// @grant    	    none
// @match    	    https://www.youtube.com/*
// @match    	    https://m.youtube.com/*
// @license         MIT
// @namespace       Remove YouTube Shorts automatically
// @author          https://greasyfork.org/en/users/895144-ed-frees
// ==/UserScript==
if (!window.location.href.includes('m.youtube')) { // Desktop
    var timeStatusOverlay = document.getElementsByTagName('H2');
    var i = 0;

    if (!localStorage.getItem("dSButtonSettings")) {
        localStorage.setItem("dSButtonSettings", "red");
    }
    var delShortsInterval;
    if (localStorage.getItem("dSButtonSettings") == 'green') {
        delShortsInterval = setInterval(delShorts, 1000);
    }

    if (document.getElementById('center').children.length != 4) {
        const div = document.createElement('DIV');
        div.id = 'dSDiv';
        div.style.position = 'absolute';
        div.style.zIndex = '99999';

        const button = document.createElement('BUTTON');
        button.id = 'dSButton';
        button.innerHTML = 'DEL Shorts';
        button.style.border = 'none';
        button.style.color = 'white';
        button.style.fontSize = '1rem';
        button.style.background = localStorage.getItem("dSButtonSettings");
        button.addEventListener('click', function () {
            if (button.style.background == 'red' || button.style.background == 'red none repeat scroll 0% 0%') {
                button.style.background = 'green';
                localStorage.setItem("dSButtonSettings", "green");
                delShortsInterval = setInterval(delShorts, 1000);
            } else if (button.style.background == 'green' || button.style.background == 'green none repeat scroll 0% 0%') {
                button.style.background = 'red';
                localStorage.setItem("dSButtonSettings", "red");
                clearInterval(delShortsInterval);
            }
        });

        div.appendChild(button);
        document.getElementById('center').appendChild(div);
    }
} else { // Mobile
    var timeStatusOverlayMobile = document.getElementsByClassName('reel-shelf-title');
    var j = 0;
    setInterval(delShortsMobile, 1000);
}
function delShorts() {
    if (i != timeStatusOverlay.length && window.location.href == 'https://www.youtube.com/feed/subscriptions') {
        i = 0;
        while (i < timeStatusOverlay.length) {
            if (timeStatusOverlay[i].innerHTML.includes('Shorts')) {
                timeStatusOverlay[i].parentElement.parentElement.parentElement.parentElement.parentElement.remove();
                continue;
            } else {
                i++;
            }
        }
    }
}
function delShortsMobile() {
    if (j != timeStatusOverlayMobile.length && window.location.href == 'https://m.youtube.com/feed/subscriptions') {
        j = 0;
        while (j < timeStatusOverlayMobile.length) {
            if (timeStatusOverlayMobile[j].innerHTML.includes('Shorts')) {
                timeStatusOverlayMobile[j].parentElement.parentElement.parentElement.parentElement.parentElement.remove();
                continue;
            } else {
                j++;
            }
        }
    }
}