Skip to content

Instantly share code, notes, and snippets.

@metruzanca
Last active August 25, 2023 17:22
Show Gist options
  • Save metruzanca/7d854649bfed479dbf7f9ecaf88f5012 to your computer and use it in GitHub Desktop.
Save metruzanca/7d854649bfed479dbf7f9ecaf88f5012 to your computer and use it in GitHub Desktop.
jira user script
// ==UserScript==
// @name Jira Column Points
// @namespace metruzanca
// @version 0.1.0
// @description Adds utilities to jira boards
// @author metruzanca
// @match https://*.atlassian.net/jira/software/c/projects/*/boards/*
// ==/UserScript==
function addStyle(cssString, container = document.head) {
const style = document.createElement('style');
style.textContent = cssString;
style.type = 'text/css';
container.append(style)
}
function countPoints(columns) {
const points = []
for(const col of columns) {
let count = 0
const estimates = col.querySelectorAll('.ghx-issue .ghx-estimate')
for(const points of estimates) {
const parsedEsitmate = +points.textContent
if (!Number.isNaN(parsedEsitmate)) {
count += parsedEsitmate
}
}
points.push(count)
}
return points
}
function main() {
addStyle(`
.custom_button {
height: calc(100% - 0.8em * 2);
margin-top: 0.8em;
border-radius: 0.2em;
background: #9063ff;
border: none;
color: black;
cursor: pointer;
}
.custom_button:hover {
background: #ac8aff;
}
`)
const daysleft = parseInt(document.querySelector('.days-left').textContent.split(' ')[0])
const button = document.createElement('button')
button.textContent = 'Get Points'
button.classList.add('custom_button')
button.onclick = () => {
const columns = document.querySelectorAll('#ghx-pool .ghx-column')
const headers = document.querySelectorAll('.ghx-column-headers .ghx-column')
const points = countPoints(columns)
const total = points.reduce((acc, curr) => acc + curr)
const done = points[points.length - 1] + points[points.length - 2]
for(let i = 0;i < headers.length; i++) {
if(i === headers.length - 1) {
const p = document.createElement('span')
p.textContent = `${points[i]}/${total}`
headers[i].append(p)
headers[i].style.display = 'flex'
} else {
const p = document.createElement('span')
p.textContent = points[i]
headers[i].append(p)
headers[i].style.display = 'flex'
}
}
document.querySelector('.days-left').textContent = `${(done/(10 - daysleft)).toFixed(2) || 1} points/day`
}
document.querySelector('.css-o1tvrz').append(button)
}
setTimeout(main, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment