-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (24 loc) · 937 Bytes
/
background.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
const iconsOn = {
32: "assets/on32.png",
128: "assets/on128.png"
}
const iconsOff = {
32: "assets/off32.png",
128: "assets/off128.png"
}
// extension enabled by default
browser.storage.local.set({"enabled": true});
browser.browserAction.setIcon({path: iconsOn})
// Turn the extension on and off, change the icon and title when doing that.
browser.browserAction.onClicked.addListener((tab) => {
// get the old extension state
browser.storage.local.get("enabled", (state) => {
// toggle the state of the extension
browser.storage.local.set({"enabled": !state.enabled});
// toggle the icon and title
const newTitle = (!state.enabled) ? "Like Everything:ON" : "Like Everything:OFF";
const iconToUse = (!state.enabled) ? iconsOn : iconsOff;
browser.browserAction.setTitle({title: newTitle});
browser.browserAction.setIcon({path: iconToUse});
})
});