Greasy Fork 还支持 简体中文。

Redirect YouTube channel to /videos

Redirect a YouTube channel home page straight to the videos tab.

  1. // ==UserScript==
  2. // @name Redirect YouTube channel to /videos
  3. // @namespace https://stojanow.com/
  4. // @match https://*.youtube.com/@*
  5. // @match http://*.youtube.com/@*
  6. // @match https://youtube.com/@*
  7. // @match http://youtube.com/@*
  8. // @run-at document-start
  9. // @grant none
  10. // @version 0.2.0
  11. // @author Piotr Stojanow (https://github.com/psto/)
  12. // @license MIT
  13. // @description Redirect a YouTube channel home page straight to the videos tab.
  14. // @icon https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQoiMtJG_PC4lsb3-GZAiTZkUXAm3VlkJC1Ag&s
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. const excludedPaths = ['/community', '/live', '/playlists', '/search', '/podcasts', '/shorts', '/streams'];
  19. let isRedirecting = false;
  20.  
  21. function redirectIfNeeded() {
  22. if (isRedirecting) return; // Prevent multiple redirections
  23.  
  24. const currentPath = window.location.pathname;
  25. const channelMatch = currentPath.match(/^\/@([^/]+)/);
  26.  
  27. if (channelMatch) {
  28. const channelName = channelMatch[1];
  29. const shouldRedirect = !excludedPaths.some(path => currentPath.startsWith(`/@${channelName}${path}`));
  30.  
  31. if (shouldRedirect && (!currentPath.endsWith('/videos') || currentPath.endsWith('/featured'))) {
  32. isRedirecting = true;
  33. const newUrl = `https://www.youtube.com/@${channelName}/videos`;
  34. window.location.href = newUrl;
  35. }
  36. }
  37. }
  38.  
  39. // Observe changes in the DOM to trigger redirection if needed
  40. const observer = new MutationObserver(redirectIfNeeded);
  41. observer.observe(document, { subtree: true, childList: true });
  42.  
  43. // Initial check for redirection
  44. redirectIfNeeded();
  45. })();