GitHub Auto-Expand Project Fields

Automatically expands collapsed custom project fields in the GitHub issue/PR sidebar (workaround for https://github.com/orgs/community/discussions/15592).

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Advertisement:

// ==UserScript==
// @name         GitHub Auto-Expand Project Fields
// @namespace    https://x.com/ArtemR
// @version      1.0
// @description  Automatically expands collapsed custom project fields in the GitHub issue/PR sidebar (workaround for https://github.com/orgs/community/discussions/15592).
// @author       Artem Russakovskii
// @license      MIT
// @match        https://github.com/*/*/issues/*
// @match        https://github.com/*/*/pull/*
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(() => {
  // Remember what we already started so MutationObserver doesn't re-trigger
  // mid-load (for PRs, a second load() aborts the in-flight fetch).
  const started = new Set();
  let path = location.pathname;

  function expand() {
    if (location.pathname !== path) {
      started.clear();
      path = location.pathname;
    }

    // Issues: React sidebar. Prefer structure/icons over English tooltip text.
    for (const section of document.querySelectorAll(
      '[class*="ProjectItemSectionViewContainer"]'
    )) {
      const btn = section.querySelector(
        'button[aria-expanded="false"]:has(.octicon-chevron-down)'
      );
      const key = section.querySelector('a[href*="/projects/"]')?.href;
      if (!btn || !key || started.has(key)) {
        continue;
      }

      started.add(key);
      btn.click();
    }

    // PRs: Catalyst widget. Use load() (fetches fields); setOpen() only flips the chevron.
    for (const widget of document.querySelectorAll(
      "collapsible-sidebar-widget:not([open])"
    )) {
      const key = widget.getAttribute("url");
      if (!key || typeof widget.load !== "function" || started.has(key)) {
        continue;
      }

      started.add(key);
      widget.load();
    }
  }

  new MutationObserver(expand).observe(document.body, {
    childList: true,
    subtree: true,
  });
  expand();
})();