-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
76 lines (57 loc) · 2.12 KB
/
content.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
74
75
76
let currSpan = document.querySelector('body > div > span');
do {
if (!currSpan) {
break;
}
const table = currSpan.querySelector('p:nth-child(2) > table:nth-child(2)');
handleCurrTable(table);
} while(hasNextSpan(currSpan));
function hasNextSpan (currNode) {
if (6 >= currNode.children.length) {
currSpan = currNode.children[5];
return true;
}
return false;
}
function handleCurrTable (currTable) {
const allStandardHours = currTable.getElementsByClassName('cb_stdHours');
const allAttendedHours = currTable.getElementsByClassName('cb_attHours');
const allAbsences = currTable.getElementsByClassName('cb_absence');
let totalDays = 0;
let totalRatio = 0;
for (let i = 0; i < allStandardHours.length; i++) {
if (allAbsences[i] && '' !== allAbsences[i].textContent.trim()) { //vacation
continue;
}
const currStdMinutes = hoursToMinutes(allStandardHours[i].textContent.trim());
if ('number' === typeof currStdMinutes && 550 > currStdMinutes && 100 < currStdMinutes) {
const currAttendedMinutes = hoursToMinutes(allAttendedHours[i].textContent.trim());
if ('number' === typeof currAttendedMinutes && 0 < currAttendedMinutes) {
totalRatio += currAttendedMinutes/currStdMinutes;
totalDays++;
}
}
}
const avgRatio = totalRatio/totalDays;
const avgMinutesDaily = 540 * avgRatio;
const avgHours = minutesToHours(avgMinutesDaily);
const row = currTable.insertRow(currTable.rows.length - 3);
const cells = {};
for (let i = 0; i < 13; i++) {
cells[i] = row.insertCell(i);
}
cells[0].innerHTML = '<b>AVG Hours of working days</b>';
cells[10].innerHTML = `<b>${avgHours}</b>`;
}
function hoursToMinutes(value) {
const a = value.split(':');
if (0 === a.length) {
return null;
}
return (Number(a[0])) * 60 + (Number(a[1]));
}
function minutesToHours(value) {
const hours = Math.floor(value / 60);
const minutes = Math.ceil(value % 60);
return hours + ':' + ('0' + minutes).slice(-2);
}