-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.js
More file actions
67 lines (61 loc) · 2.08 KB
/
stats.js
File metadata and controls
67 lines (61 loc) · 2.08 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
const toggle = document.getElementById('darkModeToggle');
// Dark mode toggle logic
chrome.storage.local.get('darkMode', (data) => {
if (data.darkMode) {
document.body.classList.add('dark');
toggle.checked = true;
}
});
toggle.addEventListener('change', () => {
const isDark = toggle.checked;
document.body.classList.toggle('dark', isDark);
chrome.storage.local.set({ darkMode: isDark });
});
// Load and display today's stats only
chrome.storage.local.get([
'tabSwitchCount',
'longestFocusStreak',
'warpTriggeredDays',
'userPoints',
'totalPenaltyToday'
], (data) => {
const switchCount = data.tabSwitchCount || 0;
const streak = data.longestFocusStreak || 0;
const warpDays = data.warpTriggeredDays || {};
const points = data.userPoints || 0;
const penalty = data.totalPenaltyToday || 0;
const netPoints = points - penalty;
const today = new Date().toISOString().split("T")[0];
const todayTriggers = warpDays[today] || 0;
document.getElementById('tabSwitches').innerText = switchCount;
document.getElementById('focusStreak').innerText = `${streak} min`;
document.getElementById('warpDays').innerText = `${todayTriggers} times today`;
document.getElementById('pointsEarned').innerText = `${points} pts`;
document.getElementById('penaltyToday').innerText = `${penalty} coins`;
document.getElementById('netPoints').innerText = `${netPoints}`;
if (typeof Chart === 'undefined') {
console.error("Chart.js not loaded. Make sure chart.min.js is included in stats.html.");
return;
}
// 🟢 Today's Focus vs Distraction Pie Chart
new Chart(document.getElementById('usageChart').getContext('2d'), {
type: 'doughnut',
data: {
labels: ['Focused Time', 'Distracted Time'],
datasets: [{
data: [streak, switchCount / 3], // Approximating distraction time
backgroundColor: ['#4caf50', '#f44336']
}]
},
options: {
responsive: true,
plugins: {
legend: { position: 'bottom' },
title: {
display: true,
text: 'Focus vs Distraction (Today)'
}
}
}
});
});