-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
35 lines (28 loc) · 1 KB
/
popup.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
const enable = document.getElementById("enable");
const enabledLabel = document.getElementById("enabled-label");
function refreshEnableCheck() {
const enabled = enable.checked;
enabledLabel.innerText = enabled ? "Activé" : "Désactivé";
return enabled;
}
// When the button is clicked, inject setPageBackgroundColor into current page
enable.addEventListener("click", async (e) => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
const enabled = refreshEnableCheck();
chrome.storage.sync.set({ enabled });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: toggleActivation,
});
});
// The body of this function will be executed as a content script inside the
// current page
function toggleActivation() {
chrome.storage.sync.get("enabled", ({ enabled }) => {
solverEnabled = enabled;
});
}
chrome.storage.sync.get("enabled", ({ enabled }) => {
enable.checked = enabled;
refreshEnableCheck();
});