-
Notifications
You must be signed in to change notification settings - Fork 2
/
popup.js
36 lines (31 loc) · 1.11 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
36
const switchElem = document.getElementById("switch")
const setLabelText = (isActivated) => {
const label = document.getElementById("label")
if (isActivated) {
label.innerText = "Gridlines enabled"
} else {
label.innerText = "Gridlines disabled"
}
}
const changeBrowserIcon = (isActivated) => {
const path = `icon/icon-${isActivated? '': 'de'}activated-`
chrome.browserAction.setIcon({
path: Object.assign({}, ...[16, 24, 32].map(e => ({[e]: path + e + '.png'})))
});
}
chrome.storage.sync.get(['isActivated'], ({ isActivated }) => {
const showActivated = typeof isActivated !== "boolean" || isActivated
switchElem.checked = showActivated
setLabelText(showActivated)
changeBrowserIcon(showActivated)
})
switchElem.addEventListener('change', (e) => {
const { checked } = e.target;
setLabelText(checked)
changeBrowserIcon(checked)
chrome.storage.sync.set({ isActivated: checked })
});
[...document.getElementsByClassName("hidden")].forEach(element => {
element.classList.remove("hidden")
setTimeout(() => element.classList.add("animated"), 100)
})