-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.js
46 lines (43 loc) · 1.7 KB
/
start.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
const modalBodySelector = 'body.modal-open';
window.fillCell = async function () {
console.log('Filling cell');
if ($(modalBodySelector).length > 0) {
$('div#modalContainer .modal-content #ehh0').val('09');
$('div#modalContainer .modal-content #emm0').val('00');
$('div#modalContainer .modal-content #xhh0').val('18');
$('div#modalContainer .modal-content #xmm0').val('00');
$('div#modalContainer .modal-content button.btn.modal-popup-btn-confirm').get(0).click();
await waitFor(() => $('div.jqi .jqiclose').css('display') !== 'block','waiting for spinner to disappear, current state: ' + $('div.jqi .jqiclose').css('display'));
} else {
console.log('no modal window was found');
}
};
window.waitFor = async function (callback, message) {
if (callback()) {
return;
}
console.log(message);
await new Promise(resolve => setTimeout(resolve, 200));
await waitFor(callback, message);
};
window.start_process = async function () {
if (!document.documentURI.indexOf('timewatch') > 0) {
console.log(document.documentURI + 'is not valid for this extension');
return;
}
let cell = $('td:contains("Entry/Exit missing")').get(0);
if (!cell) {
window.postMessage({to: 'TW_BACKGROUND', body: 'FINISH'}, '*');
return;
}
if ($(modalBodySelector).length > 0) {
console.log('found modal open');
return;
}
cell.click();
await waitFor(()=>$(modalBodySelector).length > 0, 'waiting for modal dialog to show up');
console.log(`found ${$(modalBodySelector).length} modals`);
await fillCell();
};
console.log('TimeWatch extension - start_process ');
window.start_process();