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)

目前为 2021-03-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Jump to Channel Videos
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  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 (!Boolean(link.href.match(/\/videos($|\/$)/)))
  20. link.href += "/videos";
  21. });
  22. }
  23. function set_listeners() {
  24. let 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
  25. if (subscriptions == null)
  26. return false;
  27. redirect_channel_links(subscriptions);
  28. let 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. function in_iframe() {
  46. try {
  47. return window.self !== window.top;
  48. } catch (e) {
  49. return true;
  50. }
  51. }
  52. if (!in_iframe())
  53. window.addEventListener("load", () => { repeat_until_successful(set_listeners, 100); });
  54. })();