-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
45 lines (36 loc) · 1.09 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
37
38
39
40
41
42
43
44
45
const red = "#DA3F2C";
const green = "#2C645B";
const saveId = (value) => {
chrome.storage.sync.set({ intervalId: value }, function () {});
};
const handleClick = () => {
chrome.storage.sync.get("intervalId", ({ intervalId }) => {
if (!intervalId) {
intervalId = setInterval(() => {
chrome.tabs.executeScript(null, { file: "domScript.js" });
}, 1000);
} else {
clearInterval(intervalId);
intervalId = null;
}
saveId(intervalId);
changeButtonStyle(intervalId);
});
};
const colorBorder = document.querySelector(".color-border");
const changeButtonStyle = (result) => {
if (result) {
start.style.backgroundColor = red;
colorBorder.classList.add("color-border--green");
start.innerText = "stop";
} else {
start.style.backgroundColor = green;
start.innerText = "start";
colorBorder.classList.remove("color-border--green");
}
};
document.querySelector("#start").addEventListener("click", handleClick);
// Initialize the intervalId.
chrome.storage.sync.get("intervalId", ({ intervalId }) => {
changeButtonStyle(intervalId);
});