-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
661 lines (586 loc) · 23.2 KB
/
index.html
File metadata and controls
661 lines (586 loc) · 23.2 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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&display=swap" rel="stylesheet">
<title>Cafine</title>
<link rel="stylesheet" href="cafine.css">
</head>
<body>
<header>
<div class="navbar-container">
<nav>
<div class="logo">
<img src="cafin.img/afro-nature-seeklogo.svg" alt="Site Logo">
</div>
<button class="navbar-toggle" id="navbar-toggle">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</button>
<ul class="nav-links" id="nav-links">
<li><a href="#">Home</a></li>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#benefits-section">Benefits</a></li>
<li><a href="#chatbot-container">Caffeine test</a></li>
</ul>
</nav>
</div>
</header>
<main>
<section class="hero">
<div class="hero-text">
<h1><span>Beyond the Cup</span>,<br>Discover the World of Caffeine</h1>
<p>From your morning coffee to energy drinks, learn how caffeine affects your body and mind.</p>
<div class="hero-buttons">
<button href="#introduction" class="btn-primary">Introduction</button>
<button class="btn-outline">Caffeine test→</button>
</div>
</div>
<div class="hero-image">
<div class="circle">
<img src="cafin.img/cafin 11.avif" alt="Cup of Coffee">
</div>
</div>
</section>
<section id="introduction" class="intro-section">
<div class="intro-content">
<h2>What is caffeine </h2>
<p>
Caffeine is a naturally occurring stimulant found in coffee beans, tea leaves,
cacao pods, and several other plants. It works primarily by blocking the
adenosine receptors in the brain, reducing feelings of tiredness and increasing
alertness and concentration. Caffeine is one of the most widely consumed
psychoactive substances in the world, influencing the central nervous system
to improve focus and energy levels temporarily.
</p>
<p>
While it plays a vital role in daily routines for billions of people, its effects
on the body depend on dosage, metabolism, and individual sensitivity. Understanding
how caffeine interacts with our biology helps explain why a morning cup of coffee
can be both a comfort and a science.
</p>
</div>
<div class="intro-image">
<img src="cafin.img/cafin-mol.jpg" alt="Caffeine molecular structure or coffee image" />
</div>
</section>
</section>
<!-- Add this section to your HTML after the intro section -->
<section id="benefits-section" class="benefits-section">
<h2 class="benefits-title">Benefits of Caffeine</h2>
<div class="cards-container">
<div class="glass-card">
<div class="card-icon">🧠</div>
<h3 class="card-title">Brain and Mood Boost</h3>
<p class="card-description">Caffeine helps your mind wake up, stay focused, and think more clearly. It can improve memory, learning, and reaction time, while also giving you a small mood lift to feel happier and more motivated.</p>
</div>
<div class="glass-card">
<div class="card-icon">⚡</div>
<h3 class="card-title">Energy and Physical Performance</h3>
<p class="card-description">Caffeine reduces tiredness and gives a temporary energy boost. It can also make your muscles work better, helping you perform physical activities with less effort.</p>
</div>
<div class="glass-card">
<div class="card-icon">🔥</div>
<h3 class="card-title">Metabolism and Body Function</h3>
<p class="card-description">Caffeine slightly speeds up your metabolism, which can help your body burn more calories. It also supports overall alertness, helping you stay attentive and active throughout the day.</p>
</div>
</div>
</section>
<!-- ===== MAIN CHATBOT CONTAINER ===== -->
<div id="chatbot-container" class="chatbot-container">
<!-- ===== HEADER ===== -->
<div class="chat-header">
<h1>☕ Caffeine Tracker</h1>
<p>Track your intake & stay healthy</p>
</div>
<!-- ===== MESSAGES AREA ===== -->
<div class="chat-messages" id="chat-messages">
<!-- Messages will be dynamically added here -->
</div>
<!-- ===== QUICK REPLY BUTTONS CONTAINER ===== -->
<div class="quick-replies" id="quick-replies">
<!-- Quick reply buttons will be dynamically added here -->
</div>
<!-- ===== INPUT AREA ===== -->
<div class="chat-input-container">
<input
type="text"
id="user-input"
placeholder="Type your answer here..."
autocomplete="off"
/>
<button id="send-btn">Send</button>
</div>
</div>
</main>
<footer>
<!-- Add this footer section at the end of your HTML, before closing </body> tag -->
<footer class="site-footer">
<div class="footer-container">
<!-- Footer Top Section -->
<div class="footer-top">
<div class="footer-column">
<div class="footer-logo">
<img src="cafin.img/afro-nature-seeklogo.svg" alt="Logo">
<h3>Beyond the Cup</h3>
</div>
<p class="footer-tagline">Your companion for understanding caffeine and staying healthy while working late nights.</p>
</div>
<div class="footer-column">
<h4>Quick Links</h4>
<ul class="footer-links">
<li><a href="#introduction">About Caffeine</a></li>
<li><a href="#benefits-section">Benefits & Risks</a></li>
<li><a href="#chatbot-container">Caffeine Test</a></li>
<li><a href="#https://www.mayoclinic.org/healthy-lifestyle/nutrition-and-healthy-eating/in-depth/caffeine/art-20045678">Health Tips</a></li>
</ul>
</div>
<div class="footer-column">
<h4>Resources</h4>
<ul class="footer-links">
<li><a href="#">Sleep Guidelines</a></li>
<li><a href="#">Study Tips</a></li>
<li><a href="#">Productivity Hacks</a></li>
<li><a href="#">FAQs</a></li>
</ul>
</div>
<div class="footer-column">
<h4>Stay Connected</h4>
<p class="footer-description">Get tips on healthy caffeine consumption and productivity.</p>
<div class="social-links">
<a href="https://x.com/Sidney_codes" aria-label="Twitter">
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path d="M23 3a10.9 10.9 0 01-3.14 1.53 4.48 4.48 0 00-7.86 3v1A10.66 10.66 0 013 4s-4 9 5 13a11.64 11.64 0 01-7 2c9 5 20 0 20-11.5a4.5 4.5 0 00-.08-.83A7.72 7.72 0 0023 3z"/>
</svg>
</a>
<a href="https://github.com/ngbedeworks-gif/caffine" aria-label="GitHub">
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 00-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0020 4.77 5.07 5.07 0 0019.91 1S18.73.65 16 2.48a13.38 13.38 0 00-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 005 4.77a5.44 5.44 0 00-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 009 18.13V22"/>
</svg>
</a>
<a href="#" aria-label="LinkedIn">
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path d="M16 8a6 6 0 016 6v7h-4v-7a2 2 0 00-2-2 2 2 0 00-2 2v7h-4v-7a6 6 0 016-6zM2 9h4v12H2z"/>
<circle cx="4" cy="4" r="2"/>
</svg>
</a>
</div>
</div>
</div>
<!-- Footer Bottom Section -->
<div class="footer-bottom">
<div class="footer-divider"></div>
<div class="footer-credits">
<p>© 2025 Caffeine Tracker. Built with ☕ for developers and students.</p>
<div class="footer-bottom-links">
<a href="#">Privacy Policy</a>
<span>•</span>
<a href="#">Terms of Service</a>
<span>•</span>
<a href="#">Contact</a>
</div>
</div>
</div>
</div>
</footer>
</footer>
<!-- ✅ JS for toggle -->
<script>
const toggle = document.getElementById('navbar-toggle');
const navLinks = document.getElementById('nav-links');
toggle.addEventListener('click', () => {
navLinks.classList.toggle('active');
toggle.classList.toggle('open');
});
const links = document.querySelectorAll('nav ul li a');
// --- Desktop hover functionality ---
toggle.addEventListener('mouseenter', () => {
navLinks.classList.add('active');
toggle.classList.add('open');
});
navLinks.addEventListener('mouseleave', () => {
navLinks.classList.remove('active');
toggle.classList.remove('open');
});
// --- Mobile / Touch functionality ---
toggle.addEventListener('click', () => {
navLinks.classList.toggle('active');
toggle.classList.toggle('open');
});
// Close menu on link click (works for mobile)
links.forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
toggle.classList.remove('open');
});
});
// Optional: Clicking outside closes menu (both desktop & mobile)
document.addEventListener('click', (event) => {
if (!navLinks.contains(event.target) && !toggle.contains(event.target)) {
navLinks.classList.remove('active');
toggle.classList.remove('open');
}
});
// ===== CAFFEINE DATABASE =====
// Standard caffeine content per serving in milligrams
const caffeineData = {
'coffee': 95, // per cup (8 oz)
'espresso': 63, // per shot (1 oz)
'tea': 47, // per cup (8 oz)
'green tea': 28, // per cup (8 oz)
'energy drink': 80, // per can (8 oz)
'soda': 34, // per can (12 oz)
'cola': 34, // per can (12 oz)
'dark chocolate': 12 // per oz
};
// ===== DOM ELEMENTS =====
const chatMessages = document.getElementById('chat-messages');
const userInput = document.getElementById('user-input');
const sendBtn = document.getElementById('send-btn');
const quickRepliesContainer = document.getElementById('quick-replies');
// ===== STATE MANAGEMENT =====
let conversationState = 'greeting'; // Current state of conversation
let userData = {
drinks: [], // Array to store all consumed drinks
totalCaffeine: 0, // Total caffeine in mg
lastDrinkTime: null, // Time of last drink
currentDrink: null, // Currently being processed drink
currentServings: 0 // Servings of current drink
};
// ===== INITIALIZATION =====
// Start conversation when page loads
window.addEventListener('load', () => {
setTimeout(() => {
addBotMessage("Hey there, night owl! 🦉");
setTimeout(() => {
addBotMessage("I'm here to help you track your caffeine intake so you can stay productive without overdoing it.");
setTimeout(() => {
addBotMessage("Have you had any caffeinated drinks today?");
showQuickReplies(['Yes', 'No']);
}, 1000);
}, 1000);
}, 500);
});
// ===== CORE FUNCTIONS =====
/**
* Adds a bot message to the chat
* @param {string} text - Message text to display
* @param {boolean} isTyping - Whether to show typing indicator first
*/
function addBotMessage(text, isTyping = false) {
if (isTyping) {
showTypingIndicator();
setTimeout(() => {
hideTypingIndicator();
createMessage(text, false);
}, 1000);
} else {
createMessage(text, false);
}
}
/**
* Adds a user message to the chat
* @param {string} text - Message text to display
*/
function addUserMessage(text) {
createMessage(text, true);
}
/**
* Creates and displays a message bubble
* @param {string} text - Message text
* @param {boolean} isUser - Whether message is from user
*/
function createMessage(text, isUser) {
const messageDiv = document.createElement('div');
messageDiv.className = `message ${isUser ? 'user' : 'bot'}`;
const bubble = document.createElement('div');
bubble.className = 'message-bubble';
bubble.innerHTML = text.replace(/\n/g, '<br>');
messageDiv.appendChild(bubble);
chatMessages.appendChild(messageDiv);
scrollToBottom();
}
/**
* Shows typing indicator
*/
function showTypingIndicator() {
const typingDiv = document.createElement('div');
typingDiv.className = 'message bot';
typingDiv.id = 'typing-indicator';
const indicator = document.createElement('div');
indicator.className = 'typing-indicator';
indicator.innerHTML = '<div class="typing-dot"></div><div class="typing-dot"></div><div class="typing-dot"></div>';
typingDiv.appendChild(indicator);
chatMessages.appendChild(typingDiv);
scrollToBottom();
}
/**
* Hides typing indicator
*/
function hideTypingIndicator() {
const indicator = document.getElementById('typing-indicator');
if (indicator) {
indicator.remove();
}
}
/**
* Displays quick reply buttons
* @param {Array} options - Array of button texts
*/
function showQuickReplies(options) {
clearQuickReplies();
options.forEach(option => {
const btn = document.createElement('button');
btn.className = 'quick-reply-btn';
btn.textContent = option;
btn.onclick = () => handleQuickReply(option);
quickRepliesContainer.appendChild(btn);
});
}
/**
* Clears all quick reply buttons
*/
function clearQuickReplies() {
quickRepliesContainer.innerHTML = '';
}
/**
* Scrolls chat to bottom
*/
function scrollToBottom() {
chatMessages.scrollTop = chatMessages.scrollHeight;
}
/**
* Handles quick reply button clicks
* @param {string} reply - Selected option text
*/
function handleQuickReply(reply) {
addUserMessage(reply);
clearQuickReplies();
processUserInput(reply);
}
/**
* Main input processing function
* @param {string} input - User's input text
*/
function processUserInput(input) {
const lowerInput = input.toLowerCase().trim();
// ===== STATE: GREETING =====
if (conversationState === 'greeting') {
if (lowerInput === 'yes') {
conversationState = 'asking_drink';
setTimeout(() => {
addBotMessage("Great! What did you drink? Choose from the options below or type it in:", true);
setTimeout(() => {
showQuickReplies(['Coffee', 'Tea', 'Energy Drink', 'Soda']);
}, 1200);
}, 500);
} else if (lowerInput === 'no') {
setTimeout(() => {
addBotMessage("No worries! When you do have caffeine today, come back and let me know. Stay productive! 💪", true);
conversationState = 'ended';
}, 500);
}
}
// ===== STATE: ASKING DRINK TYPE =====
else if (conversationState === 'asking_drink') {
// Check if input matches a known drink
let drinkFound = null;
for (let drink in caffeineData) {
if (lowerInput.includes(drink)) {
drinkFound = drink;
break;
}
}
if (drinkFound) {
userData.currentDrink = drinkFound;
conversationState = 'asking_servings';
setTimeout(() => {
addBotMessage(`Got it! How many servings of ${drinkFound} did you have?`, true);
setTimeout(() => {
showQuickReplies(['1', '2', '3', '4', '5+']);
}, 1200);
}, 500);
} else {
setTimeout(() => {
addBotMessage("Hmm, I don't recognize that drink. Try: coffee, tea, energy drink, soda, or cola.", true);
}, 500);
}
}
// ===== STATE: ASKING SERVINGS =====
else if (conversationState === 'asking_servings') {
let servings = parseInt(input.replace('+', ''));
if (isNaN(servings) || servings < 1) {
setTimeout(() => {
addBotMessage("Please enter a valid number of servings (e.g., 1, 2, 3).", true);
}, 500);
return;
}
userData.currentServings = servings;
conversationState = 'asking_time';
setTimeout(() => {
addBotMessage("When did you drink this? (e.g., '2 hours ago', '30 minutes ago', or 'just now')", true);
setTimeout(() => {
showQuickReplies(['Just now', '30 mins ago', '1 hour ago', '2 hours ago']);
}, 1200);
}, 500);
}
// ===== STATE: ASKING TIME =====
else if (conversationState === 'asking_time') {
const timeInfo = parseTimeInput(lowerInput);
// Calculate caffeine for this drink
const caffeineAmount = caffeineData[userData.currentDrink] * userData.currentServings;
// Store drink info
userData.drinks.push({
name: userData.currentDrink,
servings: userData.currentServings,
caffeine: caffeineAmount,
timeAgo: timeInfo
});
userData.totalCaffeine += caffeineAmount;
userData.lastDrinkTime = timeInfo;
conversationState = 'asking_more';
setTimeout(() => {
addBotMessage(`Added ${userData.currentServings} serving(s) of ${userData.currentDrink} (${caffeineAmount}mg caffeine). Did you have anything else?`, true);
setTimeout(() => {
showQuickReplies(['Yes, add more', 'No, show results']);
}, 1200);
}, 500);
}
// ===== STATE: ASKING IF MORE DRINKS =====
else if (conversationState === 'asking_more') {
if (lowerInput.includes('yes') || lowerInput.includes('more')) {
conversationState = 'asking_drink';
setTimeout(() => {
addBotMessage("What else did you drink?", true);
setTimeout(() => {
showQuickReplies(['Coffee', 'Tea', 'Energy Drink', 'Soda']);
}, 1200);
}, 500);
} else {
conversationState = 'showing_results';
setTimeout(() => {
showResults();
}, 500);
}
}
}
/**
* Parses time input into minutes
* @param {string} input - Time description
* @returns {number} Minutes ago
*/
function parseTimeInput(input) {
if (input.includes('just') || input.includes('now')) {
return 0;
} else if (input.includes('30') && input.includes('min')) {
return 30;
} else if (input.includes('1') && input.includes('hour')) {
return 60;
} else if (input.includes('2') && input.includes('hour')) {
return 120;
} else if (input.includes('3') && input.includes('hour')) {
return 180;
} else if (input.includes('4') && input.includes('hour')) {
return 240;
} else {
return 60; // Default to 1 hour
}
}
/**
* Analyzes caffeine level and generates health recommendation
* @returns {Object} Analysis result with level, status, and advice
*/
function analyzeCaffeineLevel() {
const total = userData.totalCaffeine;
let level, status, advice, emoji, color;
if (total < 100) {
level = 'Low';
status = 'Mild alertness';
emoji = '😊';
color = '#4CAF50';
advice = "You're in a good zone! Your caffeine intake is moderate. You should feel focused without any negative side effects. Keep staying hydrated and maintain good sleep habits.";
} else if (total >= 100 && total < 200) {
level = 'Moderate';
status = 'Alert & Focused';
emoji = '🚀';
color = '#2196F3';
advice = "Perfect balance! You're likely experiencing peak cognitive performance. Stay hydrated, take breaks every hour, and avoid more caffeine for the next 3-4 hours to prevent jitters.";
} else if (total >= 200 && total < 400) {
level = 'High';
status = 'Very Alert (Watch Out!)';
emoji = '⚠️';
color = '#FF9800';
advice = "You're approaching high caffeine levels. You might feel very alert but also experience increased heart rate, jitters, or anxiety. Drink plenty of water, avoid more caffeine today, and consider taking a short walk to burn off excess energy.";
} else {
level = 'Very High';
status = 'Overstimulated - Time to Rest';
emoji = '🚨';
color = '#F44336';
advice = "STOP consuming caffeine immediately! Your intake is very high and may cause anxiety, heart palpitations, difficulty sleeping, and other health issues. Drink lots of water, eat something if you haven't, avoid any more caffeine for 24 hours, and get rest as soon as possible. If you experience severe symptoms (chest pain, extreme anxiety, etc.), seek medical attention.";
}
return { level, status, advice, emoji, color, total };
}
/**
* Displays final results and recommendations
*/
function showResults() {
addBotMessage("Let me analyze your caffeine intake...", true);
setTimeout(() => {
const analysis = analyzeCaffeineLevel();
// Create summary
let summary = `<div class="summary-card">`;
summary += `<h3>${analysis.emoji} Caffeine Analysis</h3>`;
summary += `<div class="summary-item"><strong>Total Caffeine:</strong> ${analysis.total}mg</div>`;
summary += `<div class="summary-item"><strong>Level:</strong> <span style="color: ${analysis.color}; font-weight: bold;">${analysis.level}</span></div>`;
summary += `<div class="summary-item"><strong>Current State:</strong> ${analysis.status}</div>`;
summary += `<div class="summary-item" style="margin-top: 15px;"><strong>Drinks Consumed:</strong></div>`;
userData.drinks.forEach(drink => {
summary += `<div class="summary-item" style="margin-left: 10px;">• ${drink.servings}x ${drink.name} (${drink.caffeine}mg) - ${drink.timeAgo} mins ago</div>`;
});
summary += `</div>`;
createMessage(summary, false);
setTimeout(() => {
addBotMessage(`<strong>💡 Recommendation:</strong>\n\n${analysis.advice}`);
setTimeout(() => {
addBotMessage("Want to track another session? Refresh the page to start over! Stay healthy! 💪");
conversationState = 'ended';
}, 2000);
}, 1500);
}, 1500);
}
// ===== EVENT LISTENERS =====
/**
* Handle send button click
*/
sendBtn.addEventListener('click', () => {
const message = userInput.value.trim();
if (message && conversationState !== 'ended') {
addUserMessage(message);
userInput.value = '';
clearQuickReplies();
processUserInput(message);
}
});
/**
* Handle Enter key press
*/
userInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendBtn.click();
}
});
/**
* Disable input when conversation ends
*/
setInterval(() => {
if (conversationState === 'ended') {
userInput.disabled = true;
sendBtn.disabled = true;
userInput.placeholder = "Chat ended. Refresh to start again.";
}
}, 100);
</script>
</body>
</html>