Last active
February 14, 2026 20:42
-
-
Save bogorad/18b8d49dbb57e63d65f25778d72e3e8b to your computer and use it in GitHub Desktop.
Remove shorts from youtube's front 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 Auto-Hide Shorts (SPA Fixed) | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.3 | |
| // @description Auto-hide dismissible video cards (Kills Shorts/Feed) but keeps /feed/you safe | |
| // @match https://www.youtube.com/* | |
| // @match https://youtube.com/* | |
| // @exclude https://www.youtube.com/@* | |
| // @exclude https://youtube.com/@* | |
| // @exclude https://youtube.com/feed/@* | |
| // @exclude https://www.youtube.com/feed/you | |
| // @exclude https://www.youtube.com/feed/history | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
| // @grant none | |
| // @run-at document-start | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // Centralized check for all excluded pages | |
| function isExcludedPage() { | |
| const path = window.location.pathname; | |
| // 1. Channel pages (@username) | |
| // 2. The "You" page (/feed/you) - CRITICAL FIX | |
| // 3. History page (/feed/history) - often accessed from "You" | |
| return path.startsWith('/@') || | |
| path.includes('/channel/') || | |
| path === '/feed/you' || | |
| path === '/feed/history'; | |
| } | |
| function hideElements() { | |
| // If we are on a safe page, STOP immediately. | |
| if (isExcludedPage()) return; | |
| // Target the container elements in the Light DOM. | |
| // This covers Home, Subscriptions, and Sidebar recommendations. | |
| const selectors = [ | |
| 'ytd-rich-item-renderer', // Home / Modern Feed items | |
| 'ytd-grid-video-renderer', // Legacy Subscription Grid items | |
| 'ytd-compact-video-renderer', // Sidebar items | |
| 'ytd-reel-shelf-renderer', // Shorts Shelves specifically | |
| 'ytd-video-renderer' // Search results | |
| ]; | |
| const elements = document.querySelectorAll(selectors.join(',')); | |
| elements.forEach(element => { | |
| if (element.style.display !== 'none') { | |
| element.style.display = 'none'; | |
| } | |
| }); | |
| } | |
| // Initial run | |
| hideElements(); | |
| // Observer to handle dynamic loading (scrolling/navigation) | |
| const observer = new MutationObserver((mutations) => { | |
| if (isExcludedPage()) return; // Don't burn CPU on safe pages | |
| let shouldRun = false; | |
| for (const mutation of mutations) { | |
| if (mutation.addedNodes.length) { | |
| shouldRun = true; | |
| break; | |
| } | |
| } | |
| if (shouldRun) hideElements(); | |
| }); | |
| const config = { childList: true, subtree: true }; | |
| if (document.body) { | |
| observer.observe(document.body, config); | |
| } else { | |
| window.addEventListener('DOMContentLoaded', () => { | |
| observer.observe(document.body, config); | |
| }); | |
| } | |
| // Re-check logic when YouTube navigates internally (SPA) | |
| document.addEventListener('yt-navigate-finish', () => { | |
| if (isExcludedPage()) { | |
| // OPTIONAL: If you want to restore hidden elements when returning to /feed/you | |
| // You would need a "showElements()" function here, but usually | |
| // YouTube re-renders the DOM on navigation anyway. | |
| return; | |
| } | |
| hideElements(); | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment