Size
3.6 KB
Version
1.0.1
Created
Jan 24, 2026
Updated
3 months ago
1// ==UserScript==
2// @name YouTube Subscriptions Feed Cleaner
3// @description A new extension
4// @version 1.0.1
5// @match https://*.youtube.com/*
6// @icon https://www.youtube.com/s/desktop/191847ec/img/favicon_32x32.png
7// ==/UserScript==
8(function() {
9 'use strict';
10
11 console.log('YouTube Subscriptions Feed Cleaner: Extension loaded');
12
13 // Debounce function to prevent excessive calls
14 function debounce(func, wait) {
15 let timeout;
16 return function executedFunction(...args) {
17 const later = () => {
18 clearTimeout(timeout);
19 func(...args);
20 };
21 clearTimeout(timeout);
22 timeout = setTimeout(later, wait);
23 };
24 }
25
26 // Function to remove Shorts and Most relevant sections
27 function removeSections() {
28 console.log('YouTube Subscriptions Feed Cleaner: Checking for sections to remove');
29
30 let removedCount = 0;
31
32 // Find all ytd-rich-section-renderer elements (these contain the sections)
33 const richSections = document.querySelectorAll('ytd-rich-section-renderer.style-scope.ytd-rich-grid-renderer');
34
35 console.log(`YouTube Subscriptions Feed Cleaner: Found ${richSections.length} rich sections`);
36
37 richSections.forEach(section => {
38 // Check if this section contains a rich shelf with a title
39 const titleElement = section.querySelector('#title.style-scope.ytd-rich-shelf-renderer');
40
41 if (titleElement) {
42 const titleText = titleElement.textContent.trim();
43 console.log('YouTube Subscriptions Feed Cleaner: Found section with title:', titleText);
44
45 // Remove if it's "Shorts" or "Most relevant"
46 if (titleText === 'Shorts' || titleText === 'Most relevant') {
47 console.log('YouTube Subscriptions Feed Cleaner: Removing section:', titleText);
48 section.remove();
49 removedCount++;
50 }
51 }
52 });
53
54 if (removedCount > 0) {
55 console.log(`YouTube Subscriptions Feed Cleaner: Removed ${removedCount} section(s)`);
56 } else {
57 console.log('YouTube Subscriptions Feed Cleaner: No sections to remove');
58 }
59 }
60
61 // Debounced version of removeSections
62 const debouncedRemoveSections = debounce(removeSections, 500);
63
64 // Function to initialize the extension
65 function init() {
66 console.log('YouTube Subscriptions Feed Cleaner: Initializing');
67
68 // Wait a bit for content to load, then remove sections
69 setTimeout(() => {
70 removeSections();
71 }, 2000);
72
73 // Watch for DOM changes to handle dynamically loaded content
74 const observer = new MutationObserver(() => {
75 debouncedRemoveSections();
76 });
77
78 // Start observing when the main content area is available
79 const waitForContent = setInterval(() => {
80 const contentArea = document.querySelector('ytd-rich-grid-renderer');
81 if (contentArea) {
82 console.log('YouTube Subscriptions Feed Cleaner: Content area found, starting observer');
83 clearInterval(waitForContent);
84
85 observer.observe(contentArea, {
86 childList: true,
87 subtree: true
88 });
89 }
90 }, 1000);
91 }
92
93 // Wait for page to be ready
94 if (document.readyState === 'loading') {
95 document.addEventListener('DOMContentLoaded', init);
96 } else {
97 init();
98 }
99})();