-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
60 lines (48 loc) · 1.84 KB
/
Copy pathpopup.js
File metadata and controls
60 lines (48 loc) · 1.84 KB
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
document.getElementById('checkButton').addEventListener('click', async () => {
const button = document.getElementById('checkButton');
const status = document.getElementById('status');
button.disabled = true;
button.textContent = 'Processing...';
status.style.display = 'none';
try {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const results = await chrome.scripting.executeScript({
target: { tabId: tab.id },
func: checkSyncedOrders
});
const checkedCount = results[0].result;
status.textContent = `Checked ${checkedCount} completed and synced orders!`;
status.className = 'success';
status.style.display = 'block';
} catch (error) {
status.textContent = `Error: ${error.message}`;
status.className = 'error';
status.style.display = 'block';
} finally {
button.disabled = false;
button.textContent = 'Check Synced Orders';
}
});
function checkSyncedOrders() {
const rows = document.querySelectorAll('tr[mat-row]');
let checkedCount = 0;
rows.forEach((row, index) => {
const statusCell = row.querySelector('.status-label');
const statusText = statusCell ? statusCell.textContent.trim().toLowerCase() : 'no status';
const isPending = statusText === 'pending';
if (isPending) {
const syncIcon = row.querySelector('mat-icon[mattooltip="Awaiting sync"]');
const doneIcon = row.querySelector('mat-icon[mattooltip="Synced"]');
const hasSyncIcon = !!syncIcon;
const hasDoneIcon = !!doneIcon;
if (!hasSyncIcon && hasDoneIcon) {
const checkbox = row.querySelector('input.mat-checkbox-input');
if (checkbox && checkbox.getAttribute('aria-checked') === 'false') {
checkbox.click();
checkedCount++;
}
}
}
});
return checkedCount;
}