Created
March 1, 2016 10:20
-
-
Save nfourtythree/6a70ace70eaf283a5536 to your computer and use it in GitHub Desktop.
Everhour / Trello - Tracked Time and Estimate Time List totals
This file contains hidden or 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
function throttle(fn, threshhold, scope) { | |
threshhold || (threshhold = 250); | |
var last, | |
deferTimer; | |
return function () { | |
var context = scope || this; | |
var now = +new Date, | |
args = arguments; | |
if (last && now < last + threshhold) { | |
// hold on to it | |
clearTimeout(deferTimer); | |
deferTimer = setTimeout(function () { | |
last = now; | |
fn.apply(context, args); | |
}, threshhold); | |
} else { | |
last = now; | |
fn.apply(context, args); | |
} | |
}; | |
} | |
function getMins(value) { | |
splitTime = value.split(' '); | |
if (splitTime.length == 2) { | |
return (parseInt(splitTime[0].trim().substring(0, splitTime[0].trim().length -1 )) * 60) + parseInt(splitTime[1].trim().substring(0, splitTime[1].trim().length -1 )); | |
} else { | |
suffix = splitTime[0].trim().substring(splitTime[0].trim().length -1); | |
if (suffix == 'h') { | |
return parseInt(splitTime[0].trim().substring(0, splitTime[0].trim().length -1)) * 60; | |
} else if (suffix == 'm') { | |
return parseInt(splitTime[0].trim().substring(0, splitTime[0].trim().length -1)); | |
} else { | |
return 0; | |
} | |
} | |
} | |
function convertToHHMM(info) { | |
var hrs = parseInt(Number(info)); | |
var min = Math.round((Number(info)-hrs) * 60); | |
return hrs+'h '+min+'m'; | |
} | |
$('body').on('mousemove',throttle(function(){ | |
$('.list').each(function(){ | |
listHeader = $(this).find('.list-header'); | |
var used = 0; | |
var estimated = 0; | |
$(this).find('.badge.everhour-badge .badge-text').each(function(){ | |
badgeText = $(this).text().split(' of '); | |
if (badgeText.length == 2) { | |
used += getMins(badgeText[0]); | |
estimated += getMins(badgeText[1]); | |
} else { | |
used += getMins(badgeText[0]); | |
} | |
}); | |
totalHoursUsed = used / 60; | |
totalHoursEstimated = estimated / 60; | |
$(this).find('.everhour-times').remove(); | |
$(this).append("<div style='float:left;clear:left;padding:8px 10px;color:#888;width:100%;' class='everhour-times'><div style='width:50%;float:left;'><strong>Used:</strong><br>"+convertToHHMM(totalHoursUsed)+"</div><div style='width:50%;float:right;'><strong>Estimated:</strong><br>"+convertToHHMM(totalHoursEstimated)+"</div></div> "); | |
}); | |
}, 5000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment