Trello cards count

Show the quantity of cards in the list.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Trello cards count
// @namespace    http://tampermonkey.net/
// @version      1.1.2
// @description  Show the quantity of cards in the list.
// @author       Grégory M. Esberci
// @match        https://trello.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=trello.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  function debounce(func, timeout = 300) {
    let timer;
    return (...args) => {
      clearTimeout(timer);

      timer = setTimeout(() => {
        func(args);
      }, timeout);
    };
  }

  const setQuantity = (listWrapper) => {
    const className = 'trello-cards-count quiet';

    const header = listWrapper.querySelector('[data-testid=list-header] > div');
    const list = listWrapper.querySelector('[data-testid=list-cards]');

    const content = `${list.querySelectorAll('[data-testid=list-card]').length} cards`;

    let element = header.getElementsByClassName(className)[0];

    if (list.hidden) {
      if (element) element.remove();
      return;
    }

    if (!element) {
      element = document.createElement('p');

      element.className = className;
      element.style = 'padding: 0 12px';
    }

    if (content !== element.textContent) {
      element.textContent = content;
    }

    if (!header.contains(element)) {
      header.append(element);
    }
  };

  const observer = new MutationObserver(
    debounce((changes) => {
      document
        .querySelectorAll('[data-testid=list-wrapper]')
        .forEach(setQuantity);
    }, 30)
  );

  observer.observe(document.body, { childList: true, subtree: true });
})();