Last active
May 15, 2026 09:07
-
-
Save desaster/0b431e4277cddcb6e25653e232fd39a7 to your computer and use it in GitHub Desktop.
Userscript to remove "Most Relevant" and "Shorts" sections from the YouTube subscription page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Youtube subscriptions - remove "most relevant" and "shorts" sections | |
| // @namespace http://tampermonkey.net/ | |
| // @match https://*.youtube.com/* | |
| // @grant none | |
| // @version 1.2.2 | |
| // @license MIT | |
| // @author aarron-lee (original), modified by others | |
| // @description Removes the Most relevant and Shorts sections from YT subscriptions. Based on aarron-lee's script that removed only the Most relevant section. | |
| // ==/UserScript== | |
| function isSubscriptionPage() { | |
| return location.pathname === '/feed/subscriptions'; | |
| } | |
| const removeSection = () => { | |
| const desktopPaths = [ | |
| `//ytd-rich-section-renderer[.//span[text()="Most relevant"]]`, | |
| `//ytd-rich-section-renderer[.//ytd-rich-shelf-renderer[@is-shorts]]`, | |
| ] | |
| const mobilePaths = [ | |
| `//ytm-rich-shelf-renderer[.//span[text()="Most relevant"]]`, | |
| `//ytm-rich-shelf-renderer[@is-shorts]`, | |
| ] | |
| const removeSections = () => { | |
| 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 unless Subscriptions page is detected | |
| return; | |
| } | |
| const paths = isMobile() ? mobilePaths : desktopPaths | |
| for (const path of paths) { | |
| const res = document.evaluate( | |
| path, | |
| document, | |
| null, | |
| XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, | |
| null, | |
| ); | |
| for (let i = 0; i < res.snapshotLength; i++) { | |
| const e = res.snapshotItem(i) | |
| if (e instanceof Element) e.remove() | |
| } | |
| } | |
| } | |
| // yt-navigate-finish fires after YouTube's SPA navigation completes, | |
| // giving us a clean trigger point once the new page content is fully loaded | |
| document.addEventListener('yt-navigate-finish', removeSections) | |
| const o = new MutationObserver(removeSections); | |
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment