-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (54 loc) · 1.61 KB
/
app.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { App } from "./modules/counter.js";
function setTitle() {
const titleMsg = chrome.i18n.getMessage("styleTitle");
document.body.querySelector("h1").textContent = `${titleMsg} 😎`;
}
function setButton(isActive) {
const buttonMsg = chrome.i18n.getMessage("button");
let adjMsg = "";
if (isActive === "false") {
adjMsg = chrome.i18n.getMessage("active");
} else {
adjMsg = chrome.i18n.getMessage("inactive");
}
document.body.querySelector(".app-button").textContent = `${buttonMsg} ${adjMsg}`;
document.body
.querySelector(".app-button")
.setAttribute("active", `${!JSON.parse(isActive)}`);
}
(async () => {
App.setTags();
const allTheme = document.body.querySelectorAll(".theme");
allTheme.forEach((elem) => {
elem
.querySelector("button")
.addEventListener("click", () => {
chrome.storage.local.set({ theme: elem.classList.item(1) })
chrome.storage.local
.set({ active: 'true' })
.then((result) => {
setButton(isActive);
})
.catch((err) => {});
}
);
new App(elem.querySelectorAll("input"), elem.classList.item(1));
});
const button = document.body.querySelector(".app-button");
let isActive = (await chrome.storage.local.get(["active"]))["active"];
button.addEventListener("click", () => {
if (isActive === "true") {
isActive = "false";
} else {
isActive = "true";
}
chrome.storage.local
.set({ active: isActive })
.then((result) => {
setButton(isActive);
})
.catch((err) => {});
});
setTitle();
setButton(isActive);
})();