Skip to content

Instantly share code, notes, and snippets.

@suhajdab
Created July 18, 2012 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suhajdab/3134992 to your computer and use it in GitHub Desktop.
Save suhajdab/3134992 to your computer and use it in GitHub Desktop.
overview bookmarklet for ProData Hour Reporting page
var contracthours=165,hourrate=123,sum=0,now=new Date,firstday=1,nextday=now.getDate()-(now.getHours()<15?1:0),lastday=(new Date((new Date).setFullYear(now.getFullYear(),now.getMonth()+1,0))).getDate(),workdaysdone=0,workdaysleft=0,msg;for(var d=firstday;d<=lastday;d++){var day=new Date((new Date).setFullYear(now.getFullYear(),now.getMonth(),d)),weekday=day.getDay();if(weekday!==0&&weekday!==6){if(d<=nextday)workdaysdone++;else workdaysleft++}}[].slice.apply(document.querySelectorAll('span[id*="lblTimer"]')).forEach(function(a){sum+=parseFloat(a.innerText)||0});msg=contracthours+" total hours\n"+sum+" hours ("+Math.round(sum/workdaysdone*10)/10+" hours / workday) worked so far.\n"+(contracthours-sum)+" hours ("+Math.round((contracthours-sum)/workdaysleft*10)/10+" hours / workday) to go.\n"+Math.floor(sum*hourrate)+" dkk earned so far";alert(msg)
165 total hours
99.5 hours (5.5 hours / workday) worked so far.
65.5 hours (16.4 hours / workday) to go.
12345 dkk earned so far
var contracthours = 165,
hourrate = 123,
sum = 0,
now = new Date,
firstday = 1,
nextday = now.getDate() - (now.getHours() < 15 ? 1 : 0),
lastday = new Date((new Date).setFullYear(now.getFullYear(), now.getMonth() + 1, 0)).getDate(),
workdaysdone = 0,
workdaysleft = 0,
msg;
for (var d = firstday; d <= lastday; d++) {
var day = new Date((new Date).setFullYear(now.getFullYear(), now.getMonth(), d)),
weekday = day.getDay();
if (weekday !== 0 && weekday !== 6) {
if (d <= nextday) workdaysdone++;
else workdaysleft++;
}
};
[ ].slice.apply(document.querySelectorAll('span[id*="lblTimer"]')).forEach(function (el) {
sum += (parseFloat(el.innerText) || 0)
});
msg = contracthours + ' total hours\n'
+ sum + ' hours (' + Math.round(sum / workdaysdone * 10) / 10 + ' hours / workday) worked so far.\n'
+ (contracthours - sum) + ' hours (' + Math.round((contracthours - sum) / workdaysleft * 10) / 10 + ' hours / workday) to go.\n'
+ Math.floor(sum * hourrate) + ' dkk earned so far';
alert(msg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment