/
markChecked.js
48 lines (41 loc) · 1.97 KB
/
markChecked.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
// labeltitle is the human created group name
async function markTheGroups(labelTitle) {
let index = 0;
let newlyChecked = 0;
const logPort = chrome.runtime.connect({ name: 'log' });
let groupButtons = document.querySelectorAll(`button[id^=groupAddBtn]`);
for (let groupButton of groupButtons) {
continueMarking = await new Promise((resolve, _reject) => {
chrome.storage.sync.get(`continueMarking`, function (data) {
resolve(data.continueMarking);
});
});
if (!continueMarking) {
logPort.postMessage({ content: `total evaluated[${index}] added[${newlyChecked}]\nadding to group cancelled` });
return;
}
groupButton.click();
// after the groupButton is clicked, the popup is loaded, query into popup
document.querySelectorAll(`.checkInputLabel`).forEach((label) => {
// match the row of the popup to our group of interest, there are multiple groups available to check in the popup
if (label.title === labelTitle) {
label.parentNode.querySelectorAll(`[id^='groupCallout_cbxTag']`).forEach((chkbx) => {
if (!chkbx.checked) {
// if not checked, click it to have the site's angular code pick it up and process
chkbx.click();
++newlyChecked;
logPort.postMessage({ content: `added person[${index}] to group[${label.title}]` });
}
if (index % 100 == 0 && index > 0) {
logPort.postMessage({ content: `added to group [${newlyChecked} / ${index}]` });
}
});
}
});
++index;
}
// TODO: get button to change back
logPort.postMessage({ content: `total evaluated[${index}] added[${newlyChecked}]` });
}
// groupNamePassThrough is a var set in the popup.js
markTheGroups(groupNamePassthrough);