forked from igortg/browser-userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pontomais-saida.js
62 lines (47 loc) · 1.85 KB
/
pontomais-saida.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
// ==UserScript==
// @name Pontomais Saída
// @match https://app2.pontomais.com.br/*
// @description Mostra hora de saída no WebApp Pontomais
// @version 0.1
// ==/UserScript==
const MSEC_TO_MIN = 60_000;
const CHECK_LOADED_INTERVAL = 3000; //mseconds
(function() {
'use strict';
console.log("'Pontomais Saída' iniciado.");
const intervalId = setInterval(() => {
let inOutTodayElement = document.querySelector('table tr td[aria-colindex="5"] span')
if (! inOutTodayElement) {
return;
} else {
clearInterval(intervalId);
}
let clocks = parseTodayClockRecords(inOutTodayElement);
if (clocks.length != 3) {
console.log("'Retorno do almoço' não encontrado.");
return;
}
let clockOut = calculateClockOut(clocks);
displayClockOut(clockOut);
}, CHECK_LOADED_INTERVAL)
})();
function parseTodayClockRecords(inOutTodayElement) {
let inOutText = inOutTodayElement.attributes.title.value;
return inOutText.split(' - ');
}
function calculateClockOut(clocks) {
let inClock = new Date(`0 ${clocks[0]}`);
let lunchOutClock = new Date(`0 ${clocks[1]}`);
let lunchInClock = new Date(`0 ${clocks[2]}`);
let morning = (lunchOutClock - inClock) / MSEC_TO_MIN;
let expectedAfternoonMin = 480 - morning;
// Sum `expectedAfternoonMin` to lunchInClock and return.
let outClock = new Date(lunchInClock.getTime());
outClock.setTime(lunchInClock.getTime() + expectedAfternoonMin * MSEC_TO_MIN);
return outClock;
}
function displayClockOut(outDate) {
let clockOutElement = document.querySelector('table tr td[aria-colindex="9"] div > div');
let clockOutText = `${outDate.getHours()}:${outDate.getMinutes()}`;
clockOutElement.setHTML(`<span style="color:red">🌇 ${clockOutText}</span>`);
}