Greasy Fork

Greasy Fork is available in English.

Youtube Anti Shorts

shorts is a shit, fuck you youtube

当前为 2022-03-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name                Youtube Anti Shorts
// @name:zh             Youtube Anti Shorts 反短片
// @namespace           Anong0u0
// @version             0.2.3
// @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)})}

function waitElementLoad(elementSelector, isSelectAll, tryTimes = 1, interval = 0)
{
    function delay(ms){return new Promise((r)=>{setTimeout(r, ms)})}
    return new Promise(async (resolve, reject)=>
    {
        let t = 1, result;
        while(true)
        {
            if(isSelectAll) {if(result = document.querySelectorAll(elementSelector).length > 0) break;}
            else {if(result = document.querySelector(elementSelector)) break;}

            if(++t>tryTimes) {reject(); return;}
            await delay(interval);
        }
        resolve(result);
    })
}


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

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

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

    if(Remove_Shorts_Guide_Renderer)
    {
        let RSGR = ()=>
        {
            waitElementLoad("ytd-guide-entry-renderer > a[title=Shorts]", false, 10, 50).then((e)=>
            {
                e.remove();
                document.querySelector("yt-icon-button#guide-button").removeEventListener("click", RSGR);
            })
        }
        waitElementLoad("ytd-guide-entry-renderer > a[title=Shorts]", false, 10, 100)
            .then((e)=>{e.remove()})
            .catch(()=>{document.querySelector("yt-icon-button#guide-button").addEventListener("click", RSGR);})
    }
})();