Youtube Anti Shorts

shorts is a shit, fuck you youtube

目前为 2023-01-09 提交的版本。查看 最新版本

// ==UserScript==
// @name                Youtube Anti Shorts
// @name:zh             Youtube Anti Shorts 反短片
// @namespace           Anong0u0
// @version             0.3
// @description         shorts is a shit, fuck you youtube
// @description:zh      短片就是坨屎,去你的youtube
// @author              Anong0u0
// @match               *://*.youtube.com/*
// @icon                https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant               none
// @require             https://cdn.jsdelivr.net/npm/[email protected]/minified/arrive.min.js
// @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_Renderer = true;
const Hide_Shorts_Video = true;
const Redirect_Shorts_URL = true;
// ===================


Node.prototype.getParentElement = function(times = 0){return (times > 0) ? this.parentElement.getParentElement(times-1):this;}

if(Remove_Shorts_Renderer)
{
    const css = document.createElement("style");
    css.innerHTML = `
    ytd-reel-shelf-renderer.style-scope.ytd-item-section-renderer,
    ytd-mini-guide-entry-renderer[aria-label='Shorts'],
    ytd-rich-shelf-renderer[is-shorts],
    a.yt-simple-endpoint.style-scope.ytd-guide-entry-renderer[title='Shorts']
    {display:none !important}`;
    document.documentElement.append(css);
}

if(Hide_Shorts_Video)
{
    document.arrive('a[href^="/shorts"]', (e)=>
    {
        e.getParentElement(3).style.display = "none"
    });
}

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

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

    }).observe(document.body, {childList: true, subtree: true});
}