Jira Task Priority Colorizer

Change card colors based on Jira task priority and add emoji if task is in status for more than 3 days

目前為 2024-10-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Jira Task Priority Colorizer
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Change card colors based on Jira task priority and add emoji if task is in status for more than 3 days
// @author
// @include      https://*/secure/RapidBoard.jspa*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const styleContent = `
        .ghx-issue[data-priority*="P0"] {
            background-color: #FFADB0 !important;
        }
        .ghx-issue[data-priority*="P1"] {
            background-color: #FF8488 !important;
        }
        .ghx-issue[data-priority*="P2"] {
            background-color: #FFD3C6 !important;
        }
        .ghx-issue[data-priority*="P3"],
        .ghx-issue[data-priority*="P4"] {
            background-color: #FFF !important;
        }
        .stale-emoji {
            position: absolute;
            bottom: 5px;
            right: 5px;
            font-size: 32px;
            display: flex;
            align-items: center;
        }
        .stale-emoji span {
            margin-left: 5px;
            font-size: 16px;
            color: #000;
        }
        .ghx-issue {
            position: relative;
        }
    `;

    const styleElement = document.createElement('style');
    styleElement.type = 'text/css';
    styleElement.appendChild(document.createTextNode(styleContent));
    document.head.appendChild(styleElement);

    function updateCardPriorities() {
        let cards = document.querySelectorAll('.ghx-issue');

        cards.forEach(card => {
            let priorityElement = card.querySelector('.ghx-priority');
            if (priorityElement) {
                let priority = priorityElement.getAttribute('title') || priorityElement.getAttribute('aria-label') || priorityElement.innerText || priorityElement.textContent;
                if (priority) {
                    card.setAttribute('data-priority', priority);
                }
            }

            let daysElement = card.querySelector('.ghx-days');
            if (daysElement) {
                let title = daysElement.getAttribute('title');
                if (title) {
                    let daysMatch = title.match(/(\d+)\s+days?/);
                    if (daysMatch && daysMatch[1]) {
                        let daysInColumn = parseInt(daysMatch[1], 10);
                        if (daysInColumn >= 3) {
                            let existingEmoji = card.querySelector('.stale-emoji');
                            if (!existingEmoji) {
                                let emojiContainer = document.createElement('div');
                                emojiContainer.className = 'stale-emoji';

                                let emojiElement = document.createElement('span');
                                emojiElement.textContent = '💩';

                                let daysText = document.createElement('span');
                                daysText.textContent = daysInColumn + 'd';

                                emojiContainer.appendChild(emojiElement);
                                emojiContainer.appendChild(daysText);

                                card.appendChild(emojiContainer);
                            } else {
                                let daysText = existingEmoji.querySelector('span:last-child');
                                daysText.textContent = daysInColumn + ' d';
                            }
                        } else {
                            let existingEmoji = card.querySelector('.stale-emoji');
                            if (existingEmoji) {
                                existingEmoji.remove();
                            }
                        }
                    }
                }
            }
        });
    }

    const observer = new MutationObserver(() => {
        updateCardPriorities();
    });

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

    window.addEventListener('load', function() {
        updateCardPriorities();
    });

    setInterval(updateCardPriorities, 5000);
})();