Last active
January 13, 2016 13:49
-
-
Save angry-dan/11281217 to your computer and use it in GitHub Desktop.
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 JIRA natural times | |
// @namespace http://angrydan.example.com | |
// @description Allows entering times with a colon | |
// @include https://deeson.atlassian.net/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
jQuery(function(){ | |
jQuery('body').on('blur', '.tempo-time, #log-work-time-logged, #timetracking_originalestimate, #timetracking_remainingestimate', function(){ | |
var v = this.value, vp = []; | |
// Assume hours a whole number with no units is supplied. | |
if (parseInt(v) == v) { | |
v = v + 'h'; | |
} | |
// Assume fraction of hours if decimal is supplied. | |
else if (parseFloat(v) == v) { | |
vp[0] = Math.floor(v); | |
vp[1] = Math.round(60 * (v - vp[0])); | |
} | |
// Finally, assume a formatted string as h:mm | |
else { | |
vp = v.split(':'); | |
} | |
if (vp.length === 2) { | |
vp[0] = (vp[0]) ? vp[0] + 'h' : '0h'; | |
vp[1] = (vp[1]) ? vp[1] + 'm' : '0m'; | |
v = vp.join(' '); | |
} | |
this.value = v; | |
}); | |
// Add hours:mins titles to each time value in the tempo timesheet. | |
jQuery('.hours,.value-cell', '#tempo-table').each(function(){ | |
var time = parseFloat(jQuery(this).text().trim()); | |
if (!isNaN(time)) { | |
var hours = Math.floor(time) | |
var mins = Math.round((time - hours) * 60) | |
jQuery(this).attr('title', hours + ':' + String("00" + mins).slice(-2)) | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment