Jira Backlog Enhancements

Collapse/Expand all buttons, filter by sprint name

Ajankohdalta 6.8.2024. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Jira Backlog Enhancements
// @namespace    miffin
// @version      2024-08-06
// @description  Collapse/Expand all buttons, filter by sprint name
// @author       Craig Whiffin
// @match        https://*.atlassian.net/jira/*/backlog*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
// @grant        none
// @license      MIT
// ==/UserScript==
(function () {
  let JBE = (window.JBE = {});

  let top_bar = document.querySelector('div[class="_1e0c1txw _1ul9idpf"]'); // ?
  let top_bar_button_style = "css-48ccbj"; // ??

  let spawn_top_bar_container = () => {
    let outer = document.createElement("div");
    outer.className = "sc-1krxkwp-0 jcJsAc"; // ??!

    let inner = document.createElement("div");
    inner.className = "_19bv1b66 _u5f31b66"; // ???!1
    outer.appendChild(inner);

    return inner;
  };

  JBE.get_sprints = () => {
    // They keep changing the tags for these.
    return document.querySelectorAll(".ahoa2g-3, .ahoa2g-2, .css-1w12hrg"); // ???1!1?
  };

  {
    JBE.collapse_all = () => {
      document
        .querySelectorAll(
          'div[aria-controls^="backlog-accordion"][aria-expanded=true]'
        )
        .forEach((elem) => elem.click());
    };

    let container = spawn_top_bar_container();
    container.style.flexDirection = "column";

    {
      let btn = document.createElement("button");
      btn.setAttribute("id", "collapse_all_sprints");
      btn.setAttribute("onclick", "JBE.collapse_all()");
      btn.setAttribute("title", "Collapse All Sprints");
      btn.innerHTML = `
        <svg width="24" height="24" viewBox="0 0 24 24">
          <path
            d="m 13.264222,0.88771738 c -0.699238,-0.69923767 -1.834799,-0.69923767 -2.534037,0 L 1.7799447,9.8379574 c -0.6992377,0.6992386 -0.6992377,1.8347996 0,2.5340376 0.6992377,0.699238 1.834799,0.699238 2.5340367,0 L 12,4.6859761 19.686019,12.366401 c 0.699238,0.699238 1.834799,0.699238 2.534037,0 0.699237,-0.699238 0.699237,-1.834799 0,-2.5340374 l -8.950241,-8.95024 z m 8.95024,19.69052862 -8.95024,-8.950241 c -0.699238,-0.699237 -1.834799,-0.699237 -2.534037,0 l -8.9502403,8.950241 c -0.6992377,0.699237 -0.6992377,1.834799 0,2.534037 0.6992377,0.699237 1.834799,0.699237 2.5340367,0 L 12,15.426264 l 7.686019,7.680425 c 0.699238,0.699237 1.834799,0.699237 2.534037,0 0.699237,-0.699238 0.699237,-1.834799 0,-2.534037 z"
            fill="currentColor"
            fill-rule="evenodd"
          />
        </svg>
      `;
      btn.className = top_bar_button_style;
      container.appendChild(btn);
    }

    JBE.expand_all = () => {
      document
        .querySelectorAll(
          'div[aria-controls^="backlog-accordion"][aria-expanded=false]'
        )
        .forEach((elem) => {
          // only do this for visible elements, otherwise it takes forever
          if (elem.offsetParent !== null) {
            elem.click();
          }
        });
    };

    {
      let btn = document.createElement("button");
      btn.setAttribute("id", "expand_all_sprints");
      btn.setAttribute("onclick", "JBE.expand_all()");
      btn.setAttribute("title", "Expand All Sprints");
      btn.innerHTML = `
        <svg width="24" height="24" viewBox="0 0 24 24">
          <path
            d="m 13.264222,23.112282 c -0.699238,0.699238 -1.834799,0.699238 -2.534037,0 l -8.9502403,-8.95024 c -0.6992377,-0.699238 -0.6992377,-1.834799 0,-2.534037 0.6992377,-0.699238 1.834799,-0.699238 2.5340367,0 L 12,19.314024 19.686019,11.633599 c 0.699238,-0.699238 1.834799,-0.699238 2.534037,0 0.699237,0.699238 0.699237,1.834799 0,2.534037 l -8.950241,8.95024 z m 8.95024,-19.6905281 -8.95024,8.9502411 c -0.699238,0.699237 -1.834799,0.699237 -2.534037,0 L 1.7799447,3.4217539 c -0.6992377,-0.699237 -0.6992377,-1.834799 0,-2.53403702 0.6992377,-0.699237 1.834799,-0.699237 2.5340367,0 L 12,8.5737359 19.686019,0.89331088 c 0.699238,-0.699237 1.834799,-0.699237 2.534037,0 0.699237,0.69923802 0.699237,1.83479902 0,2.53403702 z"
            fill="currentColor"
            fill-rule="evenodd"
          />
        </svg>
      `;
      btn.className = top_bar_button_style;
      container.appendChild(btn);
    }

    top_bar.appendChild(container);
  }

  // filter by sprint name
  {
    JBE.show_only = (input_element) => {
      console.info("Showing only sprints matching:", input_element.value);

      JBE.get_sprints().forEach((elem) => {
        let sprint_name = elem.innerHTML.toLowerCase();
        let query = input_element.value.toLowerCase();
        let is_match = sprint_name.includes(query);
        let parent_block =
          elem.closest('div[data-testid^="software-backlog.card-list.container"]');
        parent_block.style.display = is_match ? "block" : "none";
      });
    };

    let newHTML = document.createElement("div");
    newHTML.innerHTML = `
      <input
        id="filter_by_sprint"
        class="css-1cab8vv"
        placeholder="Sprint Name"
        oninput="JBE.show_only(this)"
      />
      <div class="css-tww5fb">
        <span
          aria-hidden="true"
          class="css-1wits42"
          style="
            --icon-primary-color: currentColor;
            --icon-secondary-color: var(--ds-surface, #ffffff);
          "
          ><svg width="24" height="24" viewBox="0 0 24 24" role="presentation">
            <path
              d="M16.436 15.085l3.94 4.01a1 1 0 01-1.425 1.402l-3.938-4.006a7.5 7.5 0 111.423-1.406zM10.5 16a5.5 5.5 0 100-11 5.5 5.5 0 000 11z"
              fill="currentColor"
              fill-rule="evenodd"
            ></path></svg
        ></span>
      </div>
    `;

    newHTML.className = "css-19p3uok";
    newHTML.style.minWidth = "64px";
    top_bar.appendChild(newHTML);
  }
})();