-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
61 lines (53 loc) · 1.46 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const timeElement = document.getElementById("time");
const userName = document.getElementById("name");
const timerElement = document.getElementById("timer");
const updateTime = () => {
chrome.storage.local.get(["timer"], (res) => {
const time = res.timer ?? 0;
timerElement.textContent = `${time} Sec`;
});
const currentTime = new Date().toLocaleTimeString();
timeElement.textContent = `${currentTime}`;
};
updateTime();
setInterval(updateTime, 1000);
chrome.action.setBadgeText(
{
text: "TIME",
},
function () {
console.log("it's working");
}
);
chrome.storage.sync.get(["name"], (result) => {
if (result.name !== undefined) {
userName.innerHTML = `<h2 class="welcome_title">Welcome Back</h2>
<h2 class="username">${result.name}</h2>
`;
} else {
userName.innerHTML = `<h2 class="welcome_title">Welcome Back</h2>
`;
}
});
const startBtn = document.getElementById("start-btn");
const stopBtn = document.getElementById("stop-btn");
const resetBtn = document.getElementById("reset-btn");
startBtn.addEventListener("click", () => {
console.log("start")
chrome.storage.local.set({
isRunning: true
})
})
stopBtn.addEventListener("click", () => {
console.log("stop")
chrome.storage.local.set({
isRunning: false
})
})
resetBtn.addEventListener("click", () => {
console.log("reset")
chrome.storage.local.set({
timer : 0,
isRunning: false
})
})