-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocked.js
41 lines (35 loc) · 1.09 KB
/
blocked.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
document.addEventListener("DOMContentLoaded", () => {
const timerElement = document.getElementById("timer");
const overrideButton = document.getElementById("override");
chrome.storage.sync.get(["pomodoroEndTime"], (data) => {
if (data.pomodoroEndTime) {
updateTimer(data.pomodoroEndTime);
} else {
timerElement.textContent = "Focus mode active";
}
});
overrideButton.addEventListener("click", () => {
if (
confirm(
"Are you sure you want to override the block? This will affect your focus score."
)
) {
chrome.runtime.sendMessage({ type: "overrideBlock" });
window.history.back();
}
});
function updateTimer(endTime) {
const update = () => {
const remaining = Math.max(0, endTime - Date.now());
const minutes = Math.floor(remaining / 60000);
const seconds = Math.floor((remaining % 60000) / 1000);
timerElement.textContent = `${minutes}:${seconds
.toString()
.padStart(2, "0")}`;
if (remaining > 0) {
requestAnimationFrame(update);
}
};
update();
}
});