YouTube - automatically expand subscription list

Automatically click the "Show More" subscriptions button in the side bar

当前为 2021-11-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube - automatically expand subscription list
  3. // @description Automatically click the "Show More" subscriptions button in the side bar
  4. // @namespace https://greasyfork.org/en/scripts/367774-youtube-automatically-expand-subscription-list
  5. // @version 0.1.4
  6. // @author Valacar
  7. // @include https://www.youtube.com/*
  8. // @noframes
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const DEBUGGING = 0;
  16. const debugLog = DEBUGGING ? console.debug : function() {};
  17. const debugAssert = DEBUGGING ? console.assert : function() {};
  18.  
  19. window.addEventListener("loadstart", expandSubscriptions, true);
  20.  
  21. function expandSubscriptions() {
  22. const expanders = document.querySelectorAll("ytd-guide-collapsible-entry-renderer");
  23. debugLog("----------");
  24. debugLog("::: Found %d expanders", expanders.length);
  25. if (expanders.length == 0) {
  26. window.removeEventListener("loadstart", expandSubscriptions, true);
  27. }
  28. for (let expander of expanders) {
  29. debugLog("\t", expander);
  30. debugAssert(expander.previousSibling);
  31. const itemAbove = expander.previousSibling;
  32. const subscriptionChannel = itemAbove.querySelectorAll(
  33. 'a[href^="/c/"],a[href^="/user/"],a[href^="/feed/subscriptions/"],a[href^="/channel/"]'
  34. );
  35. if (subscriptionChannel.length) {
  36. debugLog("\t\tFound a subscription channel", subscriptionChannel[0]);
  37. const isExpanded = expander.hasAttribute("expanded");
  38. if (!isExpanded) {
  39. const expanderItem = expander.querySelector("#expander-item");
  40. if (expanderItem) {
  41. debugLog("::: Found #expander-item", expanderItem);
  42. debugLog("::: %cClicking #expander-item",
  43. "background: green; color: white; font-weight: bold;"
  44. );
  45. expanderItem.click();
  46. window.removeEventListener("loadstart", expandSubscriptions, true);
  47. } else {
  48. debugLog("::: Can't find #expander-item to click.");
  49. }
  50. return;
  51. } else {
  52. debugLog("::: Expander is already expanded. Not clicking.");
  53. }
  54. } else {
  55. debugLog("\t\tNo subscription channel link above expander.");
  56. }
  57. }
  58. }
  59.  
  60. })();