Skip to content

Instantly share code, notes, and snippets.

@dArignac
Last active January 20, 2017 08:52
Show Gist options
  • Save dArignac/65dd769a0d4368eaf835c7089ff4f3cf to your computer and use it in GitHub Desktop.
Save dArignac/65dd769a0d4368eaf835c7089ff4f3cf to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name JIRA Remaining time in percent
// @namespace http://github.com/darignac
// @version 0.6
// @description Shows the remaining time in percent. Does not work in filter views (does not get triggered).
// @author Alexander Herrmann
// @match https://jira.t-systems-mms.eu/*
// @grant none
// ==/UserScript==
const regexTimes = /(\d[w])?(\d[d])?(\d[h])?(\d[m])?/g;
function toMinutes(x) {
var minutesSum = 0;
if (x !== 'Nicht angegeben') {
var minutes = x.match(/(\d*[m])/g);
var hours = x.match(/(\d*[h])/g);
var days = x.match(/(\d*[d])/g);
var weeks = x.match(/(\d*[w])/g);
if (minutes) {
minutesSum += parseInt(minutes);
}
if (hours) {
minutesSum += parseInt(hours) * 60;
}
if (days) {
minutesSum += parseInt(days) * 8 * 60;
}
if (weeks) {
minutesSum += parseInt(weeks) * 5 * 8 * 60;
}
}
return minutesSum;
}
(function() {
'use strict';
// get booked values
var original = document.getElementById('tt_single_values_orig').innerText;
var spent = document.getElementById('tt_single_values_spent').innerText;
// if we have them, convert to minutes and estimate the remaining time in percent
if (original && spent) {
var originMin = toMinutes(original);
var spentMin = toMinutes(spent);
var remainingPercentage = 100 - parseInt((spentMin / originMin) * 100);
var info = '<span style="color: #f00">Overbooked!</span>';
if (remainingPercentage >= 0) {
info = remainingPercentage + "%";
}
// inject a new line in the time tracking container
var container = document.getElementById('tt_single_table_info');
container.innerHTML += '<dl><dt class="tt_text">Remaining:</dt><dd class="tt_values">' + info + '</dd></dl>';
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment