YouTube - automatically expand subscription list

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

  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.7
  6. // @author Valacar
  7. // @match 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.log : function(){};
  17. const debugAssert = DEBUGGING ? console.assert : function(){};
  18.  
  19. window.addEventListener("loadstart", expandSubscriptions, true);
  20.  
  21. function expandSubscriptions() {
  22. const expanderItems = document.querySelectorAll("#expander-item");
  23. debugLog("----------");
  24. debugLog("::: Found %d expander-items", expanderItems.length);
  25. for (let expander of expanderItems) {
  26. debugAssert(expander.parentNode);
  27. debugAssert(expander.parentNode.previousSibling);
  28. const lastSubscription = expander.parentNode.previousSibling;
  29. const feedItem = lastSubscription.querySelectorAll(
  30. 'a[href^="/feed/subscriptions/"],a[href^="/channel/"],a[href^="/user/"],a[href^="/c/"],a[href^="/@"]'
  31. );
  32. if (feedItem.length) {
  33. debugLog("::: Found a feed subscription link in section",
  34. expander.parentNode.closest("ytd-guide-section-renderer")
  35. );
  36. const displayProperty = window.getComputedStyle(expander).getPropertyValue("display");
  37. if (displayProperty === "block") {
  38. debugLog("::: Expander display property = ", displayProperty);
  39. debugLog("::: %cClicking expander",
  40. "background: green; color: white; font-weight: bold;"
  41. );
  42. expander.click();
  43. window.removeEventListener("loadstart", expandSubscriptions, true);
  44. return;
  45. } else {
  46. debugLog("::: Expander display property = ", displayProperty);
  47. debugLog("::: %cNot clicking since it appears to be expanded.",
  48. "background: yellow; color: #000; font-weight: bold;"
  49. );
  50. }
  51. } else {
  52. debugLog("::: No subscription feed link in section",
  53. expander.parentNode.closest("ytd-guide-section-renderer")
  54. );
  55. }
  56. }
  57. }
  58.  
  59. const observer = new MutationObserver(mutations => {
  60. if (document.querySelector('ytd-guide-section-renderer')) {
  61. expandSubscriptions();
  62. observer.disconnect();
  63. }
  64. });
  65.  
  66. observer.observe(document.body, {
  67. childList: true,
  68. subtree: true
  69. });
  70.  
  71. })();