-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (33 loc) · 1.01 KB
/
Copy pathbackground.js
File metadata and controls
38 lines (33 loc) · 1.01 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
function updateBadge(enabled) {
if (enabled) {
chrome.action.setBadgeText({ text: "" });
} else {
chrome.action.setBadgeText({ text: "OFF" });
chrome.action.setBadgeBackgroundColor({ color: "#888" });
}
}
function syncStateAndBadge(defaultOnInstall) {
chrome.storage.local.get("enabled", function (data) {
if (data.enabled === undefined && defaultOnInstall) {
chrome.storage.local.set({ enabled: true });
updateBadge(true);
return;
}
updateBadge(data.enabled !== false);
});
}
chrome.runtime.onInstalled.addListener(function (details) {
syncStateAndBadge(details.reason === "install");
});
chrome.runtime.onStartup.addListener(function () {
syncStateAndBadge(false);
});
syncStateAndBadge(false);
chrome.action.onClicked.addListener(function () {
chrome.storage.local.get("enabled", function (data) {
const currentState = data.enabled !== false;
const newState = !currentState;
chrome.storage.local.set({ enabled: newState });
updateBadge(newState);
});
});