YouTube - automatically expand subscription list

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube - automatically expand subscription list
// @description  Automatically click the "Show More" subscriptions button in the side bar
// @namespace    https://greasyfork.org/en/scripts/367774-youtube-automatically-expand-subscription-list
// @version      0.1.4
// @author       Valacar
// @include      https://www.youtube.com/*
// @noframes
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  const DEBUGGING = 0;
  const debugLog = DEBUGGING ? console.debug : function() {};
  const debugAssert = DEBUGGING ? console.assert : function() {};

  window.addEventListener("loadstart", expandSubscriptions, true);

  function expandSubscriptions() {
    const expanders = document.querySelectorAll("ytd-guide-collapsible-entry-renderer");
    debugLog("----------");
    debugLog("::: Found %d expanders", expanders.length);
    if (expanders.length == 0) {
      window.removeEventListener("loadstart", expandSubscriptions, true);
    }
    for (let expander of expanders) {
      debugLog("\t", expander);
      debugAssert(expander.previousSibling);
      const itemAbove = expander.previousSibling;
      const subscriptionChannel = itemAbove.querySelectorAll(
        'a[href^="/c/"],a[href^="/user/"],a[href^="/feed/subscriptions/"],a[href^="/channel/"]'
      );
      if (subscriptionChannel.length) {
        debugLog("\t\tFound a subscription channel", subscriptionChannel[0]);
        const isExpanded = expander.hasAttribute("expanded");
        if (!isExpanded) {
          const expanderItem = expander.querySelector("#expander-item");
          if (expanderItem) {
            debugLog("::: Found #expander-item", expanderItem);
            debugLog("::: %cClicking #expander-item",
              "background: green; color: white; font-weight: bold;"
            );
            expanderItem.click();
            window.removeEventListener("loadstart", expandSubscriptions, true);
          } else {
            debugLog("::: Can't find #expander-item to click.");
          }
          return;
        } else {
          debugLog("::: Expander is already expanded. Not clicking.");
        }
      } else {
        debugLog("\t\tNo subscription channel link above expander.");
      }
    }
  }

})();