-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudyBuddy AI.html
More file actions
575 lines (504 loc) · 28.4 KB
/
StudyBuddy AI.html
File metadata and controls
575 lines (504 loc) · 28.4 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>StudyBuddy AI - Smart Study Timer</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.4.0/css/all.min.css">
<style>
.timer-display {
font-family: 'Courier New', monospace;
font-size: 4rem;
font-weight: bold;
}
.focus-popup {
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from { transform: translateY(-20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.study-session {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.success-animation {
animation: pulse 0.5s ease-in-out;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.time-control-btn {
transition: all 0.2s ease;
}
.time-control-btn:hover {
transform: translateY(-1px);
}
.preset-btn {
transition: all 0.2s ease;
}
.preset-btn:hover {
transform: scale(1.02);
}
.preset-btn.active {
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<!-- Navigation -->
<nav class="bg-white shadow-md p-4">
<div class="container mx-auto flex justify-between items-center">
<div class="flex items-center space-x-2">
<i class="fas fa-brain text-blue-600 text-2xl"></i>
<h1 class="text-2xl font-bold text-gray-800">StudyBuddy AI</h1>
</div>
<div class="text-sm text-gray-600">
<i class="fas fa-clock mr-1"></i>
Smart Study Timer
</div>
</div>
</nav>
<!-- Main Content -->
<div class="container mx-auto p-6">
<!-- Study Timer Section -->
<div id="timerSection" class="bg-white rounded-lg shadow-lg p-8 mb-6">
<div class="text-center mb-8">
<h2 class="text-3xl font-bold text-gray-800 mb-2">Study Session</h2>
<p class="text-gray-600">Stay focused with AI-powered study assistance</p>
</div>
<!-- Timer Display -->
<div class="text-center mb-8">
<div id="timerDisplay" class="timer-display text-blue-600 mb-6">25:00</div>
<!-- Time Control Section -->
<div id="timeControls" class="mb-6">
<!-- Preset Buttons -->
<div class="mb-4">
<p class="text-sm text-gray-600 mb-3">Quick Presets:</p>
<div class="flex justify-center space-x-3 flex-wrap gap-2">
<button class="preset-btn bg-purple-500 hover:bg-purple-600 text-white px-4 py-2 rounded-lg text-sm font-semibold transition duration-200" data-minutes="15">
<i class="fas fa-zap mr-1"></i>Quick (15min)
</button>
<button class="preset-btn bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm font-semibold transition duration-200 active" data-minutes="25">
<i class="fas fa-tomato mr-1"></i>Pomodoro (25min)
</button>
<button class="preset-btn bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-semibold transition duration-200" data-minutes="45">
<i class="fas fa-clock mr-1"></i>Deep Focus (45min)
</button>
<button class="preset-btn bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg text-sm font-semibold transition duration-200" data-minutes="60">
<i class="fas fa-mountain mr-1"></i>Extended (60min)
</button>
</div>
</div>
<!-- Manual Time Adjustment -->
<div class="mb-4">
<p class="text-sm text-gray-600 mb-3">Custom Adjustment:</p>
<div class="flex justify-center items-center space-x-4">
<div class="flex items-center space-x-2">
<button id="minus25Btn" class="time-control-btn bg-red-100 hover:bg-red-200 text-red-600 w-10 h-10 rounded-full font-bold transition duration-200">
-25
</button>
<button id="minus10Btn" class="time-control-btn bg-orange-100 hover:bg-orange-200 text-orange-600 w-10 h-10 rounded-full font-bold transition duration-200">
-10
</button>
<button id="minus5Btn" class="time-control-btn bg-yellow-100 hover:bg-yellow-200 text-yellow-600 w-10 h-10 rounded-full font-bold transition duration-200">
-5
</button>
</div>
<div class="mx-4 px-4 py-2 bg-gray-100 rounded-lg">
<span id="currentTimeDisplay" class="font-semibold text-gray-800">25 min</span>
</div>
<div class="flex items-center space-x-2">
<button id="plus5Btn" class="time-control-btn bg-green-100 hover:bg-green-200 text-green-600 w-10 h-10 rounded-full font-bold transition duration-200">
+5
</button>
<button id="plus10Btn" class="time-control-btn bg-blue-100 hover:bg-blue-200 text-blue-600 w-10 h-10 rounded-full font-bold transition duration-200">
+10
</button>
<button id="plus25Btn" class="time-control-btn bg-purple-100 hover:bg-purple-200 text-purple-600 w-10 h-10 rounded-full font-bold transition duration-200">
+25
</button>
</div>
</div>
<p class="text-xs text-gray-500 mt-2">Time can only be adjusted when timer is stopped</p>
</div>
</div>
<!-- Control Buttons -->
<div class="flex justify-center space-x-4">
<button id="startBtn" class="bg-green-500 hover:bg-green-600 text-white px-8 py-3 rounded-lg font-semibold transition duration-200">
<i class="fas fa-play mr-2"></i>Start Study
</button>
<button id="pauseBtn" class="bg-yellow-500 hover:bg-yellow-600 text-white px-8 py-3 rounded-lg font-semibold transition duration-200 hidden">
<i class="fas fa-pause mr-2"></i>Pause
</button>
<button id="stopBtn" class="bg-red-500 hover:bg-red-600 text-white px-8 py-3 rounded-lg font-semibold transition duration-200 hidden">
<i class="fas fa-stop mr-2"></i>Stop
</button>
<button id="resetBtn" class="bg-gray-500 hover:bg-gray-600 text-white px-8 py-3 rounded-lg font-semibold transition duration-200">
<i class="fas fa-redo mr-2"></i>Reset
</button>
</div>
</div>
<!-- Current Session Info -->
<div id="sessionInfo" class="bg-blue-50 rounded-lg p-4 text-center hidden">
<p class="text-blue-800 font-semibold">Current Session</p>
<p class="text-blue-600">Started: <span id="sessionStart"></span></p>
<p class="text-blue-600">Focus Score: <span id="focusScore">100%</span></p>
</div>
</div>
<!-- Study Subject Input -->
<div class="bg-white rounded-lg shadow-lg p-6 mb-6">
<h3 class="text-xl font-bold text-gray-800 mb-4">What are you studying today?</h3>
<div class="flex space-x-4">
<input type="text" id="studySubject" placeholder="e.g., Mathematics, History, Programming..."
class="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<button id="setSubjectBtn" class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded-lg font-semibold transition duration-200">
Set Subject
</button>
</div>
<div id="currentSubject" class="mt-3 text-green-600 font-semibold hidden"></div>
</div>
<!-- Study Sessions History -->
<div class="bg-white rounded-lg shadow-lg p-6">
<h3 class="text-xl font-bold text-gray-800 mb-4">
<i class="fas fa-history mr-2"></i>Study History
</h3>
<div id="sessionsHistory" class="space-y-3">
<p class="text-gray-500 text-center py-8">No study sessions yet. Start your first session!</p>
</div>
</div>
</div>
<!-- Focus Check Popup -->
<div id="focusPopup" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg p-8 max-w-md mx-4 focus-popup">
<div class="text-center mb-6">
<i class="fas fa-brain text-blue-600 text-4xl mb-3"></i>
<h3 class="text-2xl font-bold text-gray-800">Focus Check!</h3>
<p class="text-gray-600">Time for a quick focus assessment</p>
</div>
<div id="focusQuestion" class="bg-blue-50 rounded-lg p-4 mb-6">
<p class="text-blue-800 font-semibold">What topic are you currently studying?</p>
</div>
<textarea id="focusAnswer" placeholder="Type your answer here..."
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 mb-4"></textarea>
<div class="flex space-x-3">
<button id="submitFocusBtn" class="flex-1 bg-green-500 hover:bg-green-600 text-white py-3 rounded-lg font-semibold transition duration-200">
Submit Answer
</button>
<button id="skipFocusBtn" class="flex-1 bg-gray-400 hover:bg-gray-500 text-white py-3 rounded-lg font-semibold transition duration-200">
Skip
</button>
</div>
</div>
</div>
<!-- Success Message -->
<div id="successMessage" class="fixed top-4 right-4 bg-green-500 text-white px-6 py-3 rounded-lg shadow-lg hidden success-animation">
<i class="fas fa-check-circle mr-2"></i>
<span id="successText">Great job!</span>
</div>
<script>
class StudyBuddyAI {
constructor() {
this.timer = null;
this.totalTime = 25 * 60; // Default 25 minutes in seconds
this.timeLeft = this.totalTime;
this.isRunning = false;
this.sessionStart = null;
this.currentSubject = '';
this.focusChecks = [];
this.focusCheckInterval = null;
this.sessionsData = JSON.parse(localStorage.getItem('studyBuddySessions')) || [];
this.focusQuestions = [
"What main concept are you currently learning?",
"Summarize what you just read in one sentence.",
"What topic are you currently studying?",
"What's the most important point from your current study material?",
"Can you explain the last concept you studied?",
"What questions do you have about the current topic?",
"How does this topic relate to what you studied before?",
"What's one key takeaway from your current study session?"
];
this.initializeEventListeners();
this.loadSessionsHistory();
this.updateTimeDisplay();
}
initializeEventListeners() {
// Timer controls
document.getElementById('startBtn').addEventListener('click', () => this.startTimer());
document.getElementById('pauseBtn').addEventListener('click', () => this.pauseTimer());
document.getElementById('stopBtn').addEventListener('click', () => this.stopTimer());
document.getElementById('resetBtn').addEventListener('click', () => this.resetTimer());
// Time adjustment buttons
document.getElementById('plus5Btn').addEventListener('click', () => this.adjustTime(5));
document.getElementById('plus10Btn').addEventListener('click', () => this.adjustTime(10));
document.getElementById('plus25Btn').addEventListener('click', () => this.adjustTime(25));
document.getElementById('minus5Btn').addEventListener('click', () => this.adjustTime(-5));
document.getElementById('minus10Btn').addEventListener('click', () => this.adjustTime(-10));
document.getElementById('minus25Btn').addEventListener('click', () => this.adjustTime(-25));
// Preset buttons
document.querySelectorAll('.preset-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const minutes = parseInt(e.target.closest('button').dataset.minutes);
this.setPresetTime(minutes);
});
});
// Other controls
document.getElementById('setSubjectBtn').addEventListener('click', () => this.setSubject());
document.getElementById('submitFocusBtn').addEventListener('click', () => this.submitFocusCheck());
document.getElementById('skipFocusBtn').addEventListener('click', () => this.skipFocusCheck());
// Enter key support
document.getElementById('studySubject').addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.setSubject();
});
document.getElementById('focusAnswer').addEventListener('keypress', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
this.submitFocusCheck();
}
});
}
adjustTime(minutes) {
if (this.isRunning) {
this.showSuccess('Cannot adjust time while timer is running!');
return;
}
const newTotalMinutes = Math.max(5, Math.min(120, Math.floor(this.totalTime / 60) + minutes));
this.totalTime = newTotalMinutes * 60;
this.timeLeft = this.totalTime;
this.updateTimeDisplay();
this.updateCurrentTimeDisplay();
this.updatePresetButtons();
this.showSuccess(`Timer set to ${newTotalMinutes} minutes`);
}
setPresetTime(minutes) {
if (this.isRunning) {
this.showSuccess('Cannot change preset while timer is running!');
return;
}
this.totalTime = minutes * 60;
this.timeLeft = this.totalTime;
this.updateTimeDisplay();
this.updateCurrentTimeDisplay();
this.updatePresetButtons();
this.showSuccess(`Timer set to ${minutes} minutes`);
}
updatePresetButtons() {
const currentMinutes = Math.floor(this.totalTime / 60);
document.querySelectorAll('.preset-btn').forEach(btn => {
btn.classList.remove('active');
if (parseInt(btn.dataset.minutes) === currentMinutes) {
btn.classList.add('active');
}
});
}
updateCurrentTimeDisplay() {
const minutes = Math.floor(this.totalTime / 60);
document.getElementById('currentTimeDisplay').textContent = `${minutes} min`;
}
updateTimeDisplay() {
const minutes = Math.floor(this.timeLeft / 60);
const seconds = this.timeLeft % 60;
document.getElementById('timerDisplay').textContent =
`${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
updateTimeControlsVisibility() {
const timeControls = document.getElementById('timeControls');
if (this.isRunning) {
timeControls.style.opacity = '0.5';
timeControls.style.pointerEvents = 'none';
} else {
timeControls.style.opacity = '1';
timeControls.style.pointerEvents = 'auto';
}
}
setSubject() {
const subjectInput = document.getElementById('studySubject');
const subject = subjectInput.value.trim();
if (subject) {
this.currentSubject = subject;
document.getElementById('currentSubject').textContent = `Current Subject: ${subject}`;
document.getElementById('currentSubject').classList.remove('hidden');
subjectInput.value = '';
this.showSuccess('Subject set successfully!');
}
}
startTimer() {
if (!this.currentSubject) {
alert('Please set your study subject first!');
return;
}
this.isRunning = true;
this.sessionStart = new Date();
this.focusChecks = [];
// Update UI
document.getElementById('startBtn').classList.add('hidden');
document.getElementById('pauseBtn').classList.remove('hidden');
document.getElementById('stopBtn').classList.remove('hidden');
document.getElementById('sessionInfo').classList.remove('hidden');
document.getElementById('sessionStart').textContent = this.sessionStart.toLocaleTimeString();
this.updateTimeControlsVisibility();
// Start timer
this.timer = setInterval(() => this.updateTimer(), 1000);
// Schedule focus checks
this.scheduleFocusCheck();
this.showSuccess('Study session started!');
}
pauseTimer() {
this.isRunning = false;
clearInterval(this.timer);
clearTimeout(this.focusCheckInterval);
document.getElementById('startBtn').classList.remove('hidden');
document.getElementById('pauseBtn').classList.add('hidden');
document.getElementById('startBtn').innerHTML = '<i class="fas fa-play mr-2"></i>Resume';
this.updateTimeControlsVisibility();
}
stopTimer() {
this.isRunning = false;
clearInterval(this.timer);
clearTimeout(this.focusCheckInterval);
// Calculate session data
const sessionDuration = this.totalTime - this.timeLeft;
const focusScore = this.calculateFocusScore();
// Save session
this.saveSession(sessionDuration, focusScore);
// Reset UI
this.resetTimer();
this.showSuccess('Study session completed!');
}
resetTimer() {
this.isRunning = false;
clearInterval(this.timer);
clearTimeout(this.focusCheckInterval);
this.timeLeft = this.totalTime;
this.updateTimeDisplay();
document.getElementById('startBtn').classList.remove('hidden');
document.getElementById('pauseBtn').classList.add('hidden');
document.getElementById('stopBtn').classList.add('hidden');
document.getElementById('sessionInfo').classList.add('hidden');
document.getElementById('startBtn').innerHTML = '<i class="fas fa-play mr-2"></i>Start Study';
this.updateTimeControlsVisibility();
this.showSuccess('Timer reset!');
}
updateTimer() {
if (this.timeLeft > 0) {
this.timeLeft--;
this.updateTimeDisplay();
} else {
this.stopTimer();
this.showSuccess('Time\'s up! Great job studying!');
}
}
scheduleFocusCheck() {
if (this.isRunning) {
// Random interval between 3-7 minutes
const interval = (Math.random() * 4 + 3) * 60 * 1000;
this.focusCheckInterval = setTimeout(() => {
this.showFocusCheck();
this.scheduleFocusCheck();
}, interval);
}
}
showFocusCheck() {
if (!this.isRunning) return;
const randomQuestion = this.focusQuestions[Math.floor(Math.random() * this.focusQuestions.length)];
document.getElementById('focusQuestion').innerHTML = `<p class="text-blue-800 font-semibold">${randomQuestion}</p>`;
document.getElementById('focusAnswer').value = '';
document.getElementById('focusPopup').classList.remove('hidden');
}
submitFocusCheck() {
const answer = document.getElementById('focusAnswer').value.trim();
this.focusChecks.push({
question: document.getElementById('focusQuestion').textContent,
answer: answer,
timestamp: new Date(),
answered: answer.length > 0
});
document.getElementById('focusPopup').classList.add('hidden');
this.updateFocusScore();
if (answer.length > 0) {
this.showSuccess('Great focus! Keep it up!');
} else {
this.showSuccess('Focus check completed!');
}
}
skipFocusCheck() {
this.focusChecks.push({
question: document.getElementById('focusQuestion').textContent,
answer: '',
timestamp: new Date(),
answered: false
});
document.getElementById('focusPopup').classList.add('hidden');
this.updateFocusScore();
}
calculateFocusScore() {
if (this.focusChecks.length === 0) return 100;
const answered = this.focusChecks.filter(check => check.answered).length;
return Math.round((answered / this.focusChecks.length) * 100);
}
updateFocusScore() {
const score = this.calculateFocusScore();
document.getElementById('focusScore').textContent = `${score}%`;
}
saveSession(duration, focusScore) {
const session = {
id: Date.now(),
subject: this.currentSubject,
duration: duration,
plannedDuration: this.totalTime,
focusScore: focusScore,
focusChecks: this.focusChecks.length,
date: new Date().toISOString(),
summary: this.generateSessionSummary(duration, focusScore)
};
this.sessionsData.unshift(session);
localStorage.setItem('studyBuddySessions', JSON.stringify(this.sessionsData));
this.loadSessionsHistory();
}
generateSessionSummary(duration, focusScore) {
const minutes = Math.floor(duration / 60);
const plannedMinutes = Math.floor(this.totalTime / 60);
const subject = this.currentSubject;
const focusLevel = focusScore >= 80 ? 'Excellent' : focusScore >= 60 ? 'Good' : 'Needs improvement';
const completion = duration === this.totalTime ? 'Completed full session' : `Studied ${minutes}/${plannedMinutes} minutes`;
return `${completion} on ${subject} with ${focusLevel.toLowerCase()} focus (${focusScore}% focus score). Answered ${this.focusChecks.filter(c => c.answered).length} out of ${this.focusChecks.length} focus checks.`;
}
loadSessionsHistory() {
const historyContainer = document.getElementById('sessionsHistory');
if (this.sessionsData.length === 0) {
historyContainer.innerHTML = '<p class="text-gray-500 text-center py-8">No study sessions yet. Start your first session!</p>';
return;
}
historyContainer.innerHTML = this.sessionsData.slice(0, 5).map(session => `
<div class="bg-gray-50 rounded-lg p-4 border-l-4 border-blue-500">
<div class="flex justify-between items-start mb-2">
<h4 class="font-semibold text-gray-800">${session.subject}</h4>
<span class="text-sm text-gray-500">${new Date(session.date).toLocaleDateString()}</span>
</div>
<div class="flex items-center space-x-4 text-sm text-gray-600 mb-2">
<span><i class="fas fa-clock mr-1"></i>${Math.floor(session.duration / 60)}/${Math.floor(session.plannedDuration / 60)} min</span>
<span><i class="fas fa-target mr-1"></i>${session.focusScore}% focus</span>
<span><i class="fas fa-question-circle mr-1"></i>${session.focusChecks} checks</span>
</div>
<p class="text-sm text-gray-700">${session.summary}</p>
</div>
`).join('');
}
showSuccess(message) {
document.getElementById('successText').textContent = message;
document.getElementById('successMessage').classList.remove('hidden');
setTimeout(() => {
document.getElementById('successMessage').classList.add('hidden');
}, 3000);
}
}
// Initialize the app
document.addEventListener('DOMContentLoaded', () => {
new StudyBuddyAI();
});
</script>
</body>
</html>