Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const trackers = {};
+ const motivationalQuotes = [
+ "Every day is a new beginning.",
+ "Progress is progress, no matter how small.",
+ "You are stronger than you think.",
+ "One day at a time.",
+ "Your future self will thank you."
+ ];
+
+ // Initialize trackers from localStorage
+ document.querySelectorAll('.addiction-card').forEach(card => {
+ const type = card.querySelector('.start-btn').dataset.type;
+ trackers[type] = {
+ startDate: localStorage.getItem(`${type}_start`),
+ counter: card.querySelector('.counter')
+ };
+ updateCounter(type);
+ });
+
+ // Start button handlers
+ document.querySelectorAll('.start-btn').forEach(btn => {
+ btn.addEventListener('click', () => {
+ const type = btn.dataset.type;
+ if (!trackers[type].startDate) {
+ trackers[type].startDate = new Date().toISOString();
+ localStorage.setItem(`${type}_start`, trackers[type].startDate);
+ updateCounter(type);
+ }
+ });
+ });
+
+ // Reset button handlers
+ document.querySelectorAll('.reset-btn').forEach(btn => {
+ btn.addEventListener('click', () => {
+ const type = btn.dataset.type;
+ trackers[type].startDate = null;
+ localStorage.removeItem(`${type}_start`);
+ updateCounter(type);
+ });
+ });
+
+ // Motivation button handler
+ const motivationBtn = document.querySelector('.motivation-btn');
+ const motivationText = document.querySelector('.motivation-text');
+
+ motivationBtn.addEventListener('click', () => {
+ const randomQuote = motivationalQuotes[Math.floor(Math.random() * motivationalQuotes.length)];
+ motivationText.textContent = randomQuote;
+ motivationText.style.opacity = 0;
+ setTimeout(() => {
+ motivationText.style.opacity = 1;
+ }, 100);
+ });
+
+ function updateCounter(type) {
+ const startDate = trackers[type].startDate;
+ if (!startDate) {
+ trackers[type].counter.textContent = '0 days clean';
+ return;
+ }
+
+ const days = Math.floor((new Date() - new Date(startDate)) / (1000 * 60 * 60 * 24));
+ trackers[type].counter.textContent = `${days} days clean`;
+ }
+
+ // Update counters every minute
+ setInterval(() => {
+ Object.keys(trackers).forEach(updateCounter);
+ }, 60000);
+ });