ExpandExpandExpand++

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

  1. // ==UserScript==
  2. // @name ExpandExpandExpand++
  3. // @name:de ExpandExpandExpand++
  4. // @name:en ExpandExpandExpand++
  5. // @namespace sun/userscripts
  6. // @version 1.0.22
  7. // @description Modification of "GitHub PR: expand, expand, expand!" with multiple small improvements.
  8. // @description:de Modifikation von "GitHub PR: expand, expand, expand!" mit mehreren kleinen Verbesserungen.
  9. // @description:en Modification of "GitHub PR: expand, expand, expand!" with multiple small improvements.
  10. // @compatible chrome
  11. // @compatible edge
  12. // @compatible firefox
  13. // @compatible opera
  14. // @compatible safari
  15. // @homepageURL https://forgejo.sny.sh/sun/userscripts
  16. // @supportURL https://forgejo.sny.sh/sun/userscripts/issues
  17. // @contributionURL https://liberapay.com/sun
  18. // @contributionAmount €1.00
  19. // @author findepi, Sunny <sunny@sny.sh>
  20. // @include https://github.com/*/*/issues/*
  21. // @include https://github.com/*/*/pull/*
  22. // @match https://github.com/*/*/issues/*
  23. // @match https://github.com/*/*/pull/*
  24. // @run-at document-end
  25. // @inject-into auto
  26. // @grant none
  27. // @noframes
  28. // @icon https://forgejo.sny.sh/sun/userscripts/raw/branch/main/icons/ExpandExpandExpand++.png
  29. // @copyright 2020-present, Sunny (https://sny.sh/)
  30. // @license Hippocratic License; https://forgejo.sny.sh/sun/userscripts/src/branch/main/LICENSE.md
  31. // ==/UserScript==
  32.  
  33. (() => {
  34. if (document.getElementsByClassName("ajax-pagination-btn").length)
  35. document
  36. .getElementsByClassName("pagehead-actions")[0]
  37. .insertAdjacentHTML(
  38. "afterbegin",
  39. "<li><a id='_f_expand_expand' class='btn btn-sm'>Expand all</a></li>",
  40. );
  41. document.getElementById("_f_expand_expand").onclick = expand;
  42.  
  43. function expand() {
  44. const btnMeta = document.getElementById("_f_expand_expand");
  45. const btnLoad = Array.from(
  46. document.querySelectorAll(".ajax-pagination-btn"),
  47. ).filter((x) => x.textContent.includes("Load more"))[0];
  48. const btnWait = Array.from(
  49. document.querySelectorAll(".ajax-pagination-btn"),
  50. ).filter((x) => x.textContent.includes("Loading"))[0];
  51.  
  52. btnMeta.setAttribute("aria-disabled", "true");
  53.  
  54. if (btnLoad) {
  55. btnMeta.innerHTML = `Expanding ${btnLoad.previousElementSibling.textContent.match(/\d+/).toString()} items...`;
  56. btnLoad.click();
  57. setTimeout(expand, 25);
  58. } else if (btnWait) {
  59. setTimeout(expand, 25);
  60. } else {
  61. btnMeta.parentNode.remove();
  62. }
  63. }
  64. })();