ExpandExpandExpand++

Modification of "GitHub PR: expand, expand, expand!" with multiple small improvements.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name               ExpandExpandExpand++
// @name:de            ExpandExpandExpand++
// @name:en            ExpandExpandExpand++
// @namespace          sun/userscripts
// @version            1.0.22
// @description        Modification of "GitHub PR: expand, expand, expand!" with multiple small improvements.
// @description:de     Modifikation von "GitHub PR: expand, expand, expand!" mit mehreren kleinen Verbesserungen.
// @description:en     Modification of "GitHub PR: expand, expand, expand!" with multiple small improvements.
// @compatible         chrome
// @compatible         edge
// @compatible         firefox
// @compatible         opera
// @compatible         safari
// @homepageURL        https://forgejo.sny.sh/sun/userscripts
// @supportURL         https://forgejo.sny.sh/sun/userscripts/issues
// @contributionURL    https://liberapay.com/sun
// @contributionAmount €1.00
// @author             findepi, Sunny <[email protected]>
// @include            https://github.com/*/*/issues/*
// @include            https://github.com/*/*/pull/*
// @match              https://github.com/*/*/issues/*
// @match              https://github.com/*/*/pull/*
// @run-at             document-end
// @inject-into        auto
// @grant              none
// @noframes
// @icon               https://forgejo.sny.sh/sun/userscripts/raw/branch/main/icons/ExpandExpandExpand++.png
// @copyright          2020-present, Sunny (https://sny.sh/)
// @license            Hippocratic License; https://forgejo.sny.sh/sun/userscripts/src/branch/main/LICENSE.md
// ==/UserScript==

(() => {
  if (document.getElementsByClassName("ajax-pagination-btn").length)
    document
      .getElementsByClassName("pagehead-actions")[0]
      .insertAdjacentHTML(
        "afterbegin",
        "<li><a id='_f_expand_expand' class='btn btn-sm'>Expand all</a></li>",
      );
  document.getElementById("_f_expand_expand").onclick = expand;

  function expand() {
    const btnMeta = document.getElementById("_f_expand_expand");
    const btnLoad = Array.from(
      document.querySelectorAll(".ajax-pagination-btn"),
    ).filter((x) => x.textContent.includes("Load more"))[0];
    const btnWait = Array.from(
      document.querySelectorAll(".ajax-pagination-btn"),
    ).filter((x) => x.textContent.includes("Loading"))[0];

    btnMeta.setAttribute("aria-disabled", "true");

    if (btnLoad) {
      btnMeta.innerHTML = `Expanding ${btnLoad.previousElementSibling.textContent.match(/\d+/).toString()} items...`;
      btnLoad.click();
      setTimeout(expand, 25);
    } else if (btnWait) {
      setTimeout(expand, 25);
    } else {
      btnMeta.parentNode.remove();
    }
  }
})();