YouTube Jump to Channel Videos

Redirect links in the subscription list to videos tab instead of the home tab (only works for open in new tab/window)

  1. // ==UserScript==
  2. // @name YouTube Jump to Channel Videos
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description Redirect links in the subscription list to videos tab instead of the home tab (only works for open in new tab/window)
  6. // @author Nathaniel Wu
  7. // @include *www.youtube.com/*
  8. // @license Apache-2.0
  9. // @supportURL https://gist.github.com/Nathaniel-Wu/b9cbdc29b2b33c7d49993ef70d7993d7
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. function redirect_channel_links(subscriptions) {
  17. subscriptions.querySelectorAll('ytd-guide-entry-renderer').forEach(channel => {
  18. let link = channel.querySelector('a');
  19. if (link.hasAttribute('href') && !/\/videos\/?$/g.test(link.href))
  20. link.href += "/videos";
  21. });
  22. }
  23. const in_iframe = () => {
  24. try {
  25. return window.self !== window.top;
  26. } catch (e) {
  27. return true;
  28. }
  29. }
  30. const repeat_until_successful = (function_ptr, interval) => {
  31. if (!function_ptr())
  32. setTimeout(() => {
  33. repeat_until_successful(function_ptr, interval);
  34. }, interval);
  35. }
  36. if (!in_iframe())
  37. repeat_until_successful(() => {
  38. const subscriptions = document.querySelector('div#content > tp-yt-app-drawer#guide div#sections > ytd-guide-section-renderer:nth-of-type(2) > div#items'); // subject to change
  39. if (!Boolean(subscriptions))
  40. return false;
  41. const observer = new MutationObserver((mutationList, observer) => {
  42. for (const mutation of mutationList)
  43. redirect_channel_links(mutation.target);
  44. });
  45. redirect_channel_links(subscriptions);
  46. observer.observe(subscriptions, { childList: true, subtree: true });
  47. return true;
  48. }, 200);
  49. })();