Change card colors based on Jira task priority and add emoji if task is in status for more than 3 days
当前为
// ==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);
})();