Youtube subscriptions - remove "most relevant" section

Removes the Most relevant section from YT subscriptions, tested on both desktop and mobile

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name        Youtube subscriptions -  remove "most relevant" section
// @namespace   http://tampermonkey.net/
// @match       https://*.youtube.com/*
// @grant       none
// @version     1.1.9
// @license     MIT
// @author      aarron-lee
// @description Removes the Most relevant section from YT subscriptions, tested on both desktop and mobile
// ==/UserScript==

function isSubscriptionPage() {
    return location.pathname === '/feed/subscriptions';
}

const removeSection = () => {
    const mostRelevantNode = isMobile() ? 'ytm-rich-shelf-renderer' : 'ytd-rich-section-renderer'
    const path = `//${mostRelevantNode}[.//span[text()="Most relevant"]]`

    const o = new MutationObserver(
        () => {
            if (!isSubscriptionPage()) {
              // if user navigates to subscriptions page from another page,
              // YouTube's SPA loads the page without re-triggering userscripts.
              // thus, load the userscript for all of youtube.com, but shortcircuit the observer unless Subscriptions page is detected
              return;
            }

            const res = document.evaluate(
                path,
                document,
                null,
                XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                null,
            );
            const n = res.snapshotLength
            if(n != 1) {
                return
            }

            const e = res.snapshotItem(0)
            if(e instanceof Element) {
                e.remove()
            }
        },
    );
    o.observe(
        document.body,
        {
            childList: true,
            subtree: true,
        },
    )
}

function isMobile() {
    const url = window.location.href;

    if (url.includes('m.youtube.com')) {
        return true
    }
    return false
}

function main() {
    removeSection()
}


main()