-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
73 lines (62 loc) · 2.71 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
window.ultiProTimeCalculator = window.ultiProTimeCalculator ||
(function (window, document, undefined) {
var host = 'https://ultiprotimecalculator.azurewebsites.net/';
var popup = null;
var timeLabel = null;
var getTime = (function () {
var $t = document.getElementById('contentFrame').contentWindow.$;
var workcells = $t('.workDetailBlock').find('td > input[value="WRK"][type="text"]');
var lunchCells = $t('.workDetailBlock').find('td > input[value="LNCHP"][type="text"]');
var breakPaid = $t('.workDetailBlock').find('td > input[value="BRKP"][type="text"]');
var combined = workcells.add(lunchCells).add(breakPaid);
var allRows = $t('.workDetailBlock tr');
var filteredRows = allRows.has(combined);
var inputs = filteredRows.find('td:nth-child(4) input[type="text"]');
var hours = 0;
var minutes = 0;
$t.each(inputs, function (i, v) {
var time = v.value.split(":");
hours += +parseInt(time[0]);
minutes += parseInt(time[1]);
});
var lastClock = $t('.tsclocksui-on').last();
var lastClockTD = lastClock.parent();
if (lastClockTD.first().next().length === 0) {
var re = / (\d{2})(\d{2})(\d{2})/;
var lastClockTime = lastClock.find('input').first().val();
var matches = re.exec(lastClockTime);
var now = new Date();
var lastClockDateTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), matches[1], matches[2], matches[3]);
var diff = now - lastClockDateTime;
var hour_diff = Math.floor(diff / 1000 / 60 / 60);
diff -= hour_diff * 1000 * 60 * 60;
var min_diff = Math.floor(diff / 1000 / 60);
hours += hour_diff;
minutes += min_diff;
}
hours += Math.floor(minutes / 60);
minutes = (minutes % 60);
return {
hours: hours,
minutes: minutes
};
});
$(document).ready(function () {
var tempElement = document.createElement('div');
document.body.appendChild(tempElement);
$(tempElement).load(host + "popup.html", function () {
popup = $('#time-popup');
timeLabel = $('#time-label');
updateTime();
setInterval(updateTime, 1000);
});
function updateTime() {
var time = getTime();
var paddedMinutes = time.minutes < 10 ? ("0" + time.minutes) : time.minutes;
var timeString = time.hours + ':' + paddedMinutes;
timeLabel.html(timeString);
document.title = timeString;
}
});
return this;
}(window, document));