-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
27 lines (23 loc) · 887 Bytes
/
Copy pathbackground.js
File metadata and controls
27 lines (23 loc) · 887 Bytes
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
const set_badge = async () => {
const { autolingo_enabled } = await chrome.storage.local.get(["autolingo_enabled"]);
if (autolingo_enabled) {
chrome.action.setBadgeText({ text: "✓" });
chrome.action.setBadgeBackgroundColor({ color: "green" });
} else {
chrome.action.setBadgeText({ text: "X" });
chrome.action.setBadgeBackgroundColor({ color: "#EC5053" });
}
};
// Default to enabled on first install
chrome.storage.local.get(["autolingo_enabled"], (result) => {
if (result.autolingo_enabled === undefined) {
chrome.storage.local.set({ "autolingo_enabled": true });
}
});
// Keep the badge in sync whenever the toggle changes (no more 1s polling needed)
chrome.storage.onChanged.addListener((changes, area) => {
if (area === "local" && "autolingo_enabled" in changes) {
set_badge();
}
});
set_badge();