-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidebar.js
More file actions
162 lines (137 loc) · 5.55 KB
/
Copy pathsidebar.js
File metadata and controls
162 lines (137 loc) · 5.55 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
document.addEventListener("DOMContentLoaded", () => {
const feedback = document.getElementById("feedback");
const progressFill = document.getElementById("progressFill");
const progressLabel = document.getElementById("progressLabel");
const WEEKLY_GOAL = 25;
const timerBtn = document.getElementById("timerBtn");
const calendarBtn = document.getElementById("calendarBtn");
const themeToggle = document.getElementById("themeToggle");
const dailyTip = document.getElementById("dailyTip");
const focusCheck = document.getElementById("focusCheck");
if (focusCheck) {
focusCheck.addEventListener("click", () => {
feedback.innerText = "Focus check complete. Stay sharp!";
});
}
const reflectBtn = document.getElementById("reflectBtn");
if (reflectBtn) {
reflectBtn.addEventListener("click", () => {
const prompts = [
"What distracted you most today?",
"Which task felt most rewarding?",
"How can you make tomorrow 1% better?",
"Did you give your full attention today?",
"What’s one thing you can finish earlier tomorrow?"
];
const random = prompts[Math.floor(Math.random() * prompts.length)];
feedback.innerText = `${random}`;
});
}
function updateProgress(totalPoints) {
const percent = Math.min((totalPoints / WEEKLY_GOAL) * 100, 100);
progressFill.style.width = `${percent}%`;
progressLabel.innerText = `${totalPoints} / ${WEEKLY_GOAL} Points`;
}
if (chrome.storage) {
chrome.storage.local.get("points", (data) => {
const total = data.points || 0;
updateProgress(total);
renderAssignments(total);
});
}
// const assignments = [
// { id: 1, name: "Module 9 Quiz", due: "2025-10-28T23:59:00" },
// { id: 2, name: "Essay Draft", due: "2025-10-27T23:59:00" },
// { id: 3, name: "Project Presentation", due: "2025-10-30T23:59:00" },
// { id: 4, name: "Lab Report", due: "2025-10-31T23:59:00" }
// ];
async function renderAssignments(totalPoints) {
const assignmentsLoaded = await chrome.storage.local.get("assignments");
const assignments = assignmentsLoaded.assignments.assignmentList;
console.log("SIDEBAR ASSIGNMENTS ", assignments);
const list = document.getElementById("todoList");
if (!list) return;
list.innerHTML = "";
assignments.forEach(a => {
const due = new Date(a.dueDate);
const now = new Date();
const diffDays = Math.floor((due - now) / (1000 * 60 * 60 * 24));
if (diffDays <= 7 && diffDays >= 0) {
const card = document.createElement("div");
card.className = "todo-card";
card.innerHTML = `
<h3 class="todo-title">${a.name}</h3>
<p class="todo-date">Due: ${due.toLocaleString()}</p>
<button id="btn-${a.assignment_id}">Mark Complete</button>
<p class="points" id="points-${a.assignment_id}">${a.points} pts total</p>
`;
styleCard(card, diffDays);
list.appendChild(card);
card.querySelector(`#btn-${a.assignment_id}`).addEventListener("click", () => {
completeAssignment(a.assignment_id, a.dueDate);
});
}
});
}
function styleCard(card, diffDays) {
if (diffDays === 0) card.style.borderLeft = "5px solid red";
else if (diffDays <= 2) card.style.borderLeft = "5px solid orange";
else card.style.borderLeft = "5px solid green";
}
function completeAssignment(id, dueDate) {
const now = new Date();
const due = new Date(dueDate);
const diffDays = Math.floor((due - now) / (1000 * 60 * 60 * 24));
let points = diffDays >= 3 ? 3 : diffDays >= 1 ? 2 : 1;
chrome.storage.local.get("points", (data) => {
const total = (data.points || 0) + points;
chrome.storage.local.set({ points: total }, () => {
document.getElementById(`points-${id}`).innerText = `${total} pts total`;
feedback.innerText = `You earned ${points} point${points > 1 ? "s" : ""}!`;
updateProgress(total);
});
});
}
timerBtn.addEventListener("click", () => {
window.open(
chrome.runtime.getURL("timer.html"),
"focusTimer",
"width=420,height=520,left=200,top=100,resizable=yes,scrollbars=no"
);
});
let hidden = false;
calendarBtn.addEventListener("click", () => {
window.open(
"calendar.html",
"popupWindow",
"width=800, height=600,left=100,top=100,resizeable=yes,scrollbars=yes"
)
});
if (chrome.runtime && chrome.runtime.onMessage) {
chrome.runtime.onMessage.addListener((message) => {
if (message.action === "refreshPoints" && message.totalPoints !== undefined) {
console.log("Sidebar received refreshed points:", message.totalPoints);
updateProgress(message.totalPoints);
feedback.innerText = `Timer complete! You now have ${message.totalPoints} total points!`;
}
});
}
if (chrome.storage) {
chrome.storage.local.get("theme", (data) => {
if (data.theme === "dark") document.body.classList.add("dark-mode");
});
themeToggle.addEventListener("click", () => {
document.body.classList.toggle("dark-mode");
const mode = document.body.classList.contains("dark-mode") ? "dark" : "light";
chrome.storage.local.set({ theme: mode });
});
}
const tips = [
"Start your day early — like a true Early Bird 🌅",
"Complete one task before breakfast 🥚",
"Early work = stress-free afternoon 🌤️",
"Reward yourself for starting early ☕",
"Every morning is a new opportunity 🚀"
];
dailyTip.innerText = tips[Math.floor(Math.random() * tips.length)];
});