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)

当前为 2020-08-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Jump to Channel Videos
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  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. var link = channel.getElementsByTagName("a")[0];
  19. if (link.href.substring(link.href.length - 7) != "/videos")
  20. link.href += "/videos";
  21. });
  22. }
  23. function set_listeners() {
  24. var subscriptions = document.evaluate('//div[@id="content"]/app-drawer[@id="guide"]//div[@id="sections"]/ytd-guide-section-renderer[2]/div[@id="items"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;//subject to change
  25. if (subscriptions == null)
  26. return false;
  27. redirect_channel_links(subscriptions);
  28. var active_DOMNodeInsertion = 0;
  29. subscriptions.addEventListener("DOMNodeInserted", () => {
  30. active_DOMNodeInsertion++;
  31. setTimeout(() => {
  32. active_DOMNodeInsertion--;
  33. if (active_DOMNodeInsertion == 0)
  34. redirect_channel_links(subscriptions);
  35. }, 20);
  36. });
  37. return true;
  38. }
  39. function repeat_until_successful(function_ptr, interval) {
  40. if (!function_ptr())
  41. setTimeout(() => {
  42. repeat_until_successful(function_ptr, interval);
  43. }, interval);
  44. }
  45. window.addEventListener("load", () => { repeat_until_successful(set_listeners, 100); });
  46. })();