Created
March 6, 2023 08:32
-
-
Save xverges/5745dbf147bbc96e2ed5164ad906fa11 to your computer and use it in GitHub Desktop.
tampermonkey userscript for richer tooltips in bifocals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Display Jira titles in bifocals | |
// @namespace https://github.com/xverges | |
// @version 0.1 | |
// @description Richer tooltips on bifocals tickets | |
// @author https://github.com/xverges | |
// @match https://bifocals.streamsets.net/products/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=streamsets.net | |
// @grant GM_xmlhttpRequest | |
// @run-at document-idle | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
async function addJiraSummary(el) { | |
let jiraId = el.text.trim().split(' ')[0] | |
if (!jiraId.includes('-')) { | |
console.log('Skipping ' + jiraId) | |
return; | |
} | |
let url = `https://streamsets.atlassian.net/rest/api/2/issue/${jiraId}`; | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: url, | |
headers: { | |
"Content-Type": "application/json" | |
}, | |
onload: function(response) { | |
let result = JSON.parse(response.response); | |
if (result) { | |
let assignee = 'unassigned'; | |
if (result.fields.assignee) { | |
assignee = result.fields.assignee.displayName; | |
} | |
el.title = `${result.fields.summary} - ${assignee} - ${el.title}` | |
el.style.backgroundColor = result.fields.status.statusCategory.colorName; | |
let color = result.fields.status.statusCategory.colorName; | |
switch (color) { | |
case 'blue-gray': | |
color = 'lightskyblue'; | |
break; | |
case 'green': | |
color = 'limegreen'; | |
break; | |
default: | |
break; | |
} | |
el.style.backgroundColor = color; | |
} | |
} | |
}); | |
} | |
function updateLinks() { | |
let jiraChips = document.getElementsByClassName('chip'); | |
console.log(jiraChips); | |
for (let chip of jiraChips) { | |
addJiraSummary(chip); | |
} | |
} | |
// I do not know hwo to properly initialize this: | |
// if I use readiness, I get the list of chips but I am unable to iterate on it | |
// (it just does not happen, no errors logged in the console) | |
setTimeout(() => updateLinks(), 5000); | |
/* | |
if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") { | |
console.log(document.readyState); | |
updateLinks(); | |
} else { | |
document.addEventListener("DOMContentLoaded", function(event) { | |
console.log('in evenet listener'); | |
updateLinks(); | |
}); | |
} | |
*/ | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment