-
Notifications
You must be signed in to change notification settings - Fork 9
/
options.js
31 lines (28 loc) · 842 Bytes
/
options.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
window.onload = async () => {
const extensionOptions = await chrome.runtime.sendMessage({ target : "readCheckedFields" });
if (extensionOptions.length > 0){
extensionOptions.forEach(id => {
document.getElementById(id).checked = true;
})
}
};
function getAndSendCheckedFields() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
const checkedFields = [];
checkboxes.forEach((checkbox) => {
if (checkbox.checked) {
checkedFields.push(checkbox.id);
}
});
chrome.runtime.sendMessage({
target: "updateCheckedFields",
checkedFields,
}).then(data => {}).catch(err => {
console.log(err);
})
}
document.querySelectorAll('input[type="checkbox"]').forEach((checkbox) => {
checkbox.addEventListener("change", function () {
getAndSendCheckedFields();
});
});