Youtube Anti Shorts

shorts is a shit, fuck you youtube

目前為 2022-03-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name                Youtube Anti Shorts
// @name:zh             Youtube Anti Shorts 反短片
// @namespace           Anong0u0
// @version             0.2
// @description         shorts is a shit, fuck you youtube
// @description:zh      短片就是坨屎,去你的youtube
// @author              Anong0u0
// @include             *://*.youtube.com/*
// @icon                https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant               none
// @license             MIT
// ==/UserScript==


// ===================
// If you don't like these feature, you can turn it off with replace true to false.
// 如果你不喜歡這些功能,你可以把true改成false來關閉。

const Remove_Shorts_Guide_Renderer = true;
const Replace_Shorts_URL = true;
const Redirect_Shorts_URL = true;
// ===================


function delay(ms = 0){return new Promise((r)=>{setTimeout(r, ms)})}

(async () =>
{
    if(Redirect_Shorts_URL && window.location.pathname.indexOf("/shorts/")!=-1) window.location.replace(window.location.href.replace("/shorts/","/watch?v="))

    let tryTimes = 1;
    while(true)
    {
        if(document.querySelectorAll("ytd-guide-entry-renderer").length > 0) break;
        if(++tryTimes>10) return;
        await delay(300);
    }
    if(Remove_Shorts_Guide_Renderer) document.querySelectorAll("ytd-guide-entry-renderer").forEach((e)=>{if(e.innerText.toLowerCase()=="shorts") e.remove()})

    var oldHref = null;
    new MutationObserver(async () => // onUrlChange
    {
        if (oldHref != window.location.href)
        {
            oldHref = window.location.href

            tryTimes = 1;
            while(true)
            {
                if(document.querySelectorAll("a.ytd-thumbnail").length > 0) break;
                if(++tryTimes>10) return;
                await delay(300);
            }

            if(Replace_Shorts_URL) document.querySelectorAll("a").forEach((e)=>{e.href = e.href.replace("/shorts/","/watch?v=")})
        }
    }).observe(document.body, {childList: true, subtree: true});
})();