We have an in-house time-tracking application at the office.
We, the employees, can view an overview of our hours on a web page. This web page renders a table, with worked hours per day in table cells, which is styled as a monthly calendar. I wrote a small script which I can copy-paste in my console to get a total of hours worked too much for that month.
A relevant snippet of the HTML.
<td height="17" align="right" >
<font size="1">10</font>
<b><font size="2"> </font></b>
<a href="/something/a" class="link">
<b><font size="2" color=black>08:33 </font></b>
</a>
</td>
<td height="17" align="right" ><font size="1">11</font>
<b><font size="2"> </font></b>
<a href="/something/b" class="link">
<b><font size="2" color=black>08:25 </font></b>
</a>
</td>
The JavaScript snippet.
var elementsToParse = $(".link").find("font:not(:empty)");
var totalMinutes = 0;
$.each(elementsToParse, function(index, element) {
var text = $(element).text();
var hours = parseInt(text.substr(1, 2));
var minutes = parseInt(text.substr(3, 2));
var elementTotal = ((hours * 60) + minutes) - 480;
totalMinutes += elementTotal;
});
alert('Overtime so far: ' + totalMinutes + ' minutes');
Any thoughts on how to make the script more compact or elegant, while maybe improving readability?