Skip to content

Instantly share code, notes, and snippets.

@kwiniarski97
Last active November 23, 2020 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwiniarski97/3140f9c5bd7b0a0fda1178b9190cd836 to your computer and use it in GitHub Desktop.
Save kwiniarski97/3140f9c5bd7b0a0fda1178b9190cd836 to your computer and use it in GitHub Desktop.
Color Labels JIRA Board - Tempermonkey.
// ==UserScript==
// @name Color Labels JIRA Board
// @namespace http://tampermonkey.net/
// @version 0.1
// @description It colors the labels in JIRa.
// @author kwiniarski97
// @match *.atlassian.net/secure/RapidBoard.jspa*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const getHash = (name) => {
let hash = 0;
for (let i = 0; i < name.length; i++) {
let chr = name.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0;
}
return Math.pow(hash % 1e+20, 4);
}
const getRandomColor = (name) => {
const hash = getHash(name);
const hue = hash % 360;
const saturation = 70 + hash % (90 - 70);
return `hsla(${hue}, ${saturation}%, 40%, 1)`;
};
document.addEventListener("DOMNodeInserted", () => {
const labels = [
...document.querySelectorAll('span.ghx-extra-field[data-tooltip^=Labels]'),
...document.querySelectorAll('span.ghx-extra-field[data-tooltip^=Etykiety]')
];
labels.forEach(label => {
label.style.background = getRandomColor(label.innerText);
label.style.color = '#fff';
label.style.padding = "2px 4px";
label.style.borderRadius = "4px";
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment