-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
26 lines (22 loc) · 914 Bytes
/
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
document.addEventListener("DOMContentLoaded", function () {
const toggleSwitch = document.getElementById("focusToggle");
const statusText = document.getElementById("status");
// Check the saved focus mode state
chrome.storage.sync.get("focusMode", function (data) {
const isFocusModeOn = data.focusMode;
toggleSwitch.checked = isFocusModeOn;
updateStatusText(isFocusModeOn);
sendToggleMessage(isFocusModeOn);
});
// Toggle the focus mode state
toggleSwitch.addEventListener("change", function () {
const isFocusModeOn = toggleSwitch.checked;
updateStatusText(isFocusModeOn);
});
// Update the status text based on the focus mode state
function updateStatusText(isFocusModeOn) {
statusText.textContent = `Focus Mode: ${isFocusModeOn ? "ON" : "OFF"}`;
// Save the state to chrome.storage.sync
chrome.storage.sync.set({ focusMode: isFocusModeOn });
}
});