YouTube Subscriptions Only

Removes Home and Shorts buttons, hides Shorts content, and redirects to Subscriptions feed

  1. // ==UserScript==
  2. // @name YouTube Subscriptions Only
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4.2
  5. // @description Removes Home and Shorts buttons, hides Shorts content, and redirects to Subscriptions feed
  6. // @author SanoKei
  7. // @match https://www.youtube.com/*
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to remove Home and Shorts buttons
  15. function removeButtons() {
  16. // Target both mini-guide and regular guide entries
  17. const selectors = [
  18. 'ytd-mini-guide-entry-renderer',
  19. 'ytd-guide-entry-renderer'
  20. ];
  21.  
  22. selectors.forEach(selector => {
  23. const entries = document.querySelectorAll(selector);
  24. entries.forEach(entry => {
  25. // Check if the entry is Home or Shorts by examining its title
  26. const title = entry.querySelector('.title');
  27. if (title && (title.textContent === 'Home' || title.textContent === 'Shorts')) {
  28. entry.style.display = 'none';
  29. }
  30. });
  31. });
  32. }
  33.  
  34. // Function to hide shorts videos in subscription feed
  35. function hideShorts() {
  36. // Only run on subscription feed
  37. if (window.location.pathname !== '/feed/subscriptions') return;
  38.  
  39. // Hide individual shorts videos
  40. const videoRenderers = document.querySelectorAll('ytd-grid-video-renderer, ytd-rich-item-renderer');
  41. videoRenderers.forEach(renderer => {
  42. // Look for shorts indicator - either a "shorts" badge or shorts URL
  43. const shortsBadge = renderer.querySelector('[overlay-style="SHORTS"], [aria-label*="Shorts"]');
  44. const shortLink = renderer.querySelector('a[href*="/shorts/"]');
  45.  
  46. // If this is a shorts video, hide it
  47. if (shortsBadge || shortLink) {
  48. renderer.style.display = 'none';
  49. }
  50. });
  51.  
  52. // Find and hide entire shorts shelf/section
  53. const shortsShelves = document.querySelectorAll('ytd-rich-shelf-renderer');
  54. shortsShelves.forEach(shelf => {
  55. // Look for the title element that says "Shorts"
  56. const titleElement = shelf.querySelector('#title');
  57. if (titleElement && titleElement.textContent.trim() === 'Shorts') {
  58. // Get the parent container (usually has id="dismissible")
  59. const container = shelf.closest('#dismissible, .ytd-rich-section-renderer');
  60. if (container) {
  61. container.style.display = 'none';
  62. } else {
  63. // Hide the shelf itself if we can't find the parent container
  64. shelf.style.display = 'none';
  65. }
  66. }
  67. });
  68. }
  69.  
  70. // Function to redirect to subscriptions if on homepage
  71. function redirectToSubscriptions() {
  72. // Only redirect if we're on the homepage (not already on a video or other page)
  73. if (window.location.pathname === '/' || window.location.pathname === '/watch') {
  74. window.location.href = '/feed/subscriptions';
  75. }
  76. }
  77.  
  78. // Function to modify YouTube logo links to go to subscriptions
  79. function modifyLogoLinks() {
  80. // Target all YouTube logo links
  81. const logoLinks = document.querySelectorAll('a.yt-simple-endpoint[href="/"]');
  82.  
  83. logoLinks.forEach(link => {
  84. // Change the href attribute
  85. link.setAttribute('href', '/feed/subscriptions');
  86.  
  87. // Remove any existing click event listeners to prevent YouTube from overriding our behavior
  88. const newLink = link.cloneNode(true);
  89. link.parentNode.replaceChild(newLink, link);
  90.  
  91. // Add our own click event listener
  92. newLink.addEventListener('click', function(e) {
  93. e.preventDefault();
  94. e.stopPropagation();
  95.  
  96. // Navigate to subscriptions using YouTube's internal navigation system
  97. const app = document.querySelector('ytd-app');
  98. if (app) {
  99. app.fire('yt-navigate', {
  100. endpoint: {
  101. commandMetadata: {
  102. webCommandMetadata: {
  103. url: '/feed/subscriptions'
  104. }
  105. },
  106. browseEndpoint: {
  107. browseId: 'FEsubscriptions'
  108. }
  109. }
  110. });
  111. } else {
  112. // Fallback to regular navigation if we can't use YouTube's internal system
  113. window.location.href = '/feed/subscriptions';
  114. }
  115. });
  116. });
  117. }
  118.  
  119. // Function to force subscription feed as background for miniplayer
  120. function fixMiniplayerBackground() {
  121. // Check if we're on the homepage when miniplayer is active
  122. const miniPlayer = document.querySelector('ytd-miniplayer[active]');
  123.  
  124. if (miniPlayer && window.location.pathname === '/') {
  125. // Don't use history.pushState as it can break the miniplayer
  126. // Instead, try to load the subscriptions content without changing the URL
  127.  
  128. try {
  129. // Find YouTube's app element
  130. const app = document.querySelector('ytd-app');
  131. if (app) {
  132. // Only apply when miniplayer is present and we're on the homepage
  133. const contentContainer = document.querySelector('ytd-browse[role="main"]');
  134.  
  135. if (contentContainer) {
  136. // Load subscriptions content into the main content area
  137. // We use YouTube's internal navigation system
  138. app.fire('yt-navigate', {
  139. endpoint: {
  140. commandMetadata: {
  141. webCommandMetadata: {
  142. url: '/feed/subscriptions'
  143. }
  144. },
  145. browseEndpoint: {
  146. browseId: 'FEsubscriptions'
  147. }
  148. },
  149. // Don't actually change the URL, which would break miniplayer
  150. updateHistory: false,
  151. // Make sure miniplayer stays active
  152. preserveMiniplayerState: true
  153. });
  154. }
  155. }
  156. } catch (e) {
  157. console.error('Error fixing miniplayer background:', e);
  158. }
  159. }
  160. }
  161.  
  162. // Run the functions periodically to catch dynamic content
  163. setInterval(() => {
  164. removeButtons();
  165. modifyLogoLinks();
  166. hideShorts();
  167. fixMiniplayerBackground();
  168. }, 1000);
  169.  
  170. // Run once on initial page load
  171. removeButtons();
  172. modifyLogoLinks();
  173. hideShorts();
  174. fixMiniplayerBackground();
  175.  
  176. // Redirect if on homepage
  177. if (window.location.pathname === '/') {
  178. redirectToSubscriptions();
  179. }
  180.  
  181. // Monitor for navigation events within YouTube (for SPA behavior)
  182. const pushState = history.pushState;
  183. history.pushState = function() {
  184. pushState.apply(history, arguments);
  185.  
  186. // Check if we've navigated to the homepage
  187. if (window.location.pathname === '/') {
  188. setTimeout(redirectToSubscriptions, 100);
  189. }
  190.  
  191. // Run functions after navigation
  192. setTimeout(() => {
  193. removeButtons();
  194. modifyLogoLinks();
  195. hideShorts();
  196. fixMiniplayerBackground();
  197. }, 500);
  198. };
  199. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址