-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
65 lines (58 loc) · 1.83 KB
/
Copy pathpopup.js
File metadata and controls
65 lines (58 loc) · 1.83 KB
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
const siteInput = document.getElementById("siteInput");
const addBtn = document.getElementById("addSite");
const siteList = document.getElementById("siteList");
const startBtn = document.getElementById("startFocus");
const status = document.getElementById("status");
const rewardDiv = document.getElementById("reward");
let focusActive = false;
let timer;
// Load stored sites
chrome.storage.local.get(["blockedSites"], (data) => {
if (data.blockedSites) {
data.blockedSites.forEach(addSiteToUI);
chrome.runtime.sendMessage({ action: "updateSites", sites: data.blockedSites });
}
});
// Add site
addBtn.addEventListener("click", () => {
let site = siteInput.value.trim();
if (site) {
chrome.storage.local.get(["blockedSites"], (data) => {
let blocked = data.blockedSites || [];
blocked.push(site);
chrome.storage.local.set({ blockedSites: blocked }, () => {
addSiteToUI(site);
chrome.runtime.sendMessage({ action: "updateSites", sites: blocked });
});
siteInput.value = "";
});
}
});
function addSiteToUI(site) {
let li = document.createElement("li");
li.textContent = site;
siteList.appendChild(li);
}
// Start focus mode
startBtn.addEventListener("click", () => {
if (!focusActive) {
focusActive = true;
status.textContent = "⏳ Focus Mode ON (25 min)";
chrome.runtime.sendMessage({ action: "startFocus" });
timer = setTimeout(() => {
focusActive = false;
status.textContent = "✅ Focus Complete!";
chrome.runtime.sendMessage({ action: "stopFocus" });
showReward();
}, 25 * 60 * 1000);
}
});
// Show reward
function showReward() {
fetch("rewards.json")
.then(res => res.json())
.then(data => {
const reward = data[Math.floor(Math.random() * data.length)];
rewardDiv.innerHTML = `<b>🎉 Reward:</b> ${reward}`;
});
}