Spaces:
Running
Running
Download index.html from ishash/anycoder-9d487df6: direct link, hf CLI and curl.
- Browser
- Download file 28.1 kB
-
https://huggingface.co/spaces/ishash/anycoder-9d487df6/resolve/main/index.html
- Command line
-
hf download hf://spaces/ishash/anycoder-9d487df6/index.html
-
curl -L -o index.html https://huggingface.co/spaces/ishash/anycoder-9d487df6/resolve/main/index.html
28.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Keep Going - Motivational Habit Tracker</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&display=swap" rel="stylesheet"> | |
| <style> | |
| body { | |
| font-family: 'Outfit', sans-serif; | |
| background-color: #0f172a; | |
| overflow-x: hidden; | |
| } | |
| /* Custom Scrollbar */ | |
| ::-webkit-scrollbar { | |
| width: 8px; | |
| } | |
| ::-webkit-scrollbar-track { | |
| background: #1e293b; | |
| } | |
| ::-webkit-scrollbar-thumb { | |
| background: #4f46e5; | |
| border-radius: 4px; | |
| } | |
| /* Animations */ | |
| @keyframes float { | |
| 0% { transform: translateY(0px); } | |
| 50% { transform: translateY(-10px); } | |
| 100% { transform: translateY(0px); } | |
| } | |
| @keyframes pulse-glow { | |
| 0%, 100% { box-shadow: 0 0 15px rgba(79, 70, 229, 0.2); } | |
| 50% { box-shadow: 0 0 25px rgba(79, 70, 229, 0.6); } | |
| } | |
| @keyframes slideIn { | |
| from { opacity: 0; transform: translateY(20px); } | |
| to { opacity: 1; transform: translateY(0); } | |
| } | |
| @keyframes confetti-fall { | |
| 0% { transform: translateY(-100vh) rotate(0deg); } | |
| 100% { transform: translateY(100vh) rotate(720deg); } | |
| } | |
| .glass-panel { | |
| background: rgba(30, 41, 59, 0.7); | |
| backdrop-filter: blur(12px); | |
| -webkit-backdrop-filter: blur(12px); | |
| border: 1px solid rgba(255, 255, 255, 0.1); | |
| } | |
| .habit-card { | |
| transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| .habit-card:hover { | |
| transform: translateY(-2px); | |
| border-color: rgba(99, 102, 241, 0.5); | |
| } | |
| .checkbox-wrapper input:checked + div { | |
| background-color: #4f46e5; | |
| border-color: #4f46e5; | |
| } | |
| .checkbox-wrapper input:checked + div svg { | |
| display: block; | |
| } | |
| .progress-ring__circle { | |
| transition: stroke-dashoffset 0.5s ease-in-out; | |
| transform: rotate(-90deg); | |
| transform-origin: 50% 50%; | |
| } | |
| /* Confetti Particle */ | |
| .confetti { | |
| position: fixed; | |
| width: 10px; | |
| height: 10px; | |
| background-color: #f00; | |
| z-index: 9999; | |
| pointer-events: none; | |
| } | |
| /* Gradient Text */ | |
| .text-gradient { | |
| background: linear-gradient(to right, #818cf8, #c084fc, #f472b6); | |
| -webkit-background-clip: text; | |
| -webkit-text-fill-color: transparent; | |
| } | |
| .streak-flame { | |
| animation: flicker 1.5s infinite alternate; | |
| } | |
| @keyframes flicker { | |
| 0%, 100% { opacity: 1; transform: scale(1); } | |
| 50% { opacity: 0.8; transform: scale(1.1); } | |
| } | |
| </style> | |
| </head> | |
| <body class="text-slate-200 min-h-screen flex flex-col relative"> | |
| <!-- Background Canvas for Particles --> | |
| <canvas id="bgCanvas" class="fixed top-0 left-0 w-full h-full -z-10 opacity-30"></canvas> | |
| <!-- Header --> | |
| <header class="w-full p-6 flex justify-between items-center glass-panel sticky top-0 z-50"> | |
| <div class="flex items-center gap-3"> | |
| <div class="w-10 h-10 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center shadow-lg shadow-indigo-500/30"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" /> | |
| </svg> | |
| </div> | |
| <div> | |
| <h1 class="text-2xl font-bold tracking-tight text-white">Keep Going</h1> | |
| <p class="text-xs text-slate-400 uppercase tracking-wider">Daily Momentum Builder</p> | |
| </div> | |
| </div> | |
| <div class="hidden md:flex items-center gap-4"> | |
| <div class="text-right"> | |
| <div id="current-date" class="text-sm font-semibold text-slate-300"></div> | |
| <div id="current-time" class="text-xs text-slate-500 font-mono"></div> | |
| </div> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="px-4 py-2 rounded-full bg-slate-800 hover:bg-slate-700 border border-slate-700 text-xs font-medium transition-colors flex items-center gap-2 group"> | |
| <span>Built with anycoder</span> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 group-hover:translate-x-1 transition-transform" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" /> | |
| </svg> | |
| </a> | |
| </div> | |
| </header> | |
| <!-- Main Content --> | |
| <main class="flex-grow container mx-auto px-4 py-8 flex flex-col lg:flex-row gap-8"> | |
| <!-- Left Column: Stats & Motivation --> | |
| <aside class="w-full lg:w-1/3 flex flex-col gap-6"> | |
| <!-- Daily Progress Card --> | |
| <div class="glass-panel rounded-2xl p-6 relative overflow-hidden group"> | |
| <div class="absolute top-0 right-0 w-32 h-32 bg-indigo-500/20 rounded-full blur-3xl -mr-10 -mt-10 transition-all group-hover:bg-indigo-500/30"></div> | |
| <h2 class="text-lg font-semibold mb-4 flex items-center gap-2"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-indigo-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 3.055A9.001 9.001 0 1020.945 13H11V3.055z" /> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.488 9H15V3.512A9.025 9.025 0 0120.488 9z" /> | |
| </svg> | |
| Daily Progress | |
| </h2> | |
| <div class="flex items-center justify-center py-4"> | |
| <div class="relative w-40 h-40"> | |
| <svg class="w-full h-full" viewBox="0 0 100 100"> | |
| <circle class="text-slate-700 stroke-current" stroke-width="8" cx="50" cy="50" r="40" fill="transparent"></circle> | |
| <circle id="progress-ring" class="text-indigo-500 progress-ring__circle stroke-current" stroke-width="8" stroke-linecap="round" cx="50" cy="50" r="40" fill="transparent" stroke-dasharray="251.2" stroke-dashoffset="251.2"></circle> | |
| </svg> | |
| <div class="absolute top-0 left-0 w-full h-full flex flex-col items-center justify-center"> | |
| <span id="progress-text" class="text-3xl font-bold text-white">0%</span> | |
| <span class="text-xs text-slate-400 uppercase">Done</span> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="mt-4 text-center"> | |
| <p id="motivational-quote" class="text-sm text-slate-300 italic">"Small steps every day."</p> | |
| </div> | |
| </div> | |
| <!-- Streak Card --> | |
| <div class="glass-panel rounded-2xl p-6 flex items-center justify-between"> | |
| <div> | |
| <p class="text-sm text-slate-400 uppercase tracking-wide">Current Streak</p> | |
| <div class="flex items-baseline gap-1 mt-1"> | |
| <span id="streak-count" class="text-4xl font-bold text-white">12</span> | |
| <span class="text-sm text-slate-400">days</span> | |
| </div> | |
| </div> | |
| <div class="h-12 w-12 rounded-full bg-orange-500/20 flex items-center justify-center streak-flame"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-orange-500" viewBox="0 0 20 20" fill="currentColor"> | |
| <path fill-rule="evenodd" d="M12.395 2.553a1 1 0 00-1.45-.385c-.345.23-.614.558-.822.88-.214.33-.403.713-.57 1.116-.334.804-.614 1.768-.84 2.734a31.365 31.365 0 00-.613 3.58 2.64 2.64 0 01-.945-1.067c-.328-.68-.398-1.534-.398-2.654A1 1 0 005.05 6.05 6.981 6.981 0 003 11a7 7 0 1011.95-4.95c-.592-.591-.98-.985-1.348-1.467-.363-.476-.724-1.063-1.207-2.03zM12.12 15.12A3 3 0 017 13s.879.5 2.5.5c0-1 .5-4 1.25-4.5.5 1 .786 1.293 1.371 1.879A2.99 2.99 0 0113 13a2.99 2.99 0 01-.879 2.121z" clip-rule="evenodd" /> | |
| </svg> | |
| </div> | |
| </div> | |
| <!-- Add Habit Form --> | |
| <div class="glass-panel rounded-2xl p-6"> | |
| <h3 class="text-md font-semibold mb-4 text-white">Add New Habit</h3> | |
| <form id="add-habit-form" class="flex flex-col gap-3"> | |
| <input type="text" id="new-habit-input" placeholder="e.g., Read 10 pages..." class="w-full bg-slate-800/50 border border-slate-700 rounded-lg px-4 py-3 text-sm text-white placeholder-slate-500 focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 transition-all"> | |
| <div class="flex gap-2"> | |
| <select id="new-habit-category" class="bg-slate-800/50 border border-slate-700 rounded-lg px-3 py-3 text-sm text-slate-300 focus:outline-none focus:border-indigo-500 flex-grow"> | |
| <option value="health">Health</option> | |
| <option value="work">Work</option> | |
| <option value="learning">Learning</option> | |
| <option value="mindfulness">Mindfulness</option> | |
| </select> | |
| <button type="submit" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center justify-center"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"> | |
| <path fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" clip-rule="evenodd" /> | |
| </svg> | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| </aside> | |
| <!-- Right Column: Habit List --> | |
| <section class="w-full lg:w-2/3"> | |
| <div class="flex justify-between items-end mb-6"> | |
| <div> | |
| <h2 class="text-2xl font-bold text-white">Your Habits</h2> | |
| <p class="text-slate-400 text-sm mt-1">Consistency is key to mastery.</p> | |
| </div> | |
| <div class="flex gap-2"> | |
| <button onclick="filterHabits('all')" class="filter-btn active px-3 py-1 rounded-full text-xs font-medium bg-indigo-600 text-white transition-all">All</button> | |
| <button onclick="filterHabits('active')" class="filter-btn px-3 py-1 rounded-full text-xs font-medium bg-slate-800 text-slate-400 hover:bg-slate-700 transition-all">Active</button> | |
| <button onclick="filterHabits('completed')" class="filter-btn px-3 py-1 rounded-full text-xs font-medium bg-slate-800 text-slate-400 hover:bg-slate-700 transition-all">Completed</button> | |
| </div> | |
| </div> | |
| <div id="habit-list" class="grid grid-cols-1 gap-4"> | |
| <!-- Habits will be injected here via JS --> | |
| </div> | |
| <!-- Empty State (Hidden by default) --> | |
| <div id="empty-state" class="hidden flex flex-col items-center justify-center py-12 text-center"> | |
| <div class="w-16 h-16 bg-slate-800 rounded-full flex items-center justify-center mb-4"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-slate-600" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" /> | |
| </svg> | |
| </div> | |
| <h3 class="text-lg font-medium text-white">All caught up!</h3> | |
| <p class="text-slate-500 text-sm mt-1">You've completed all your habits for today.</p> | |
| </div> | |
| </section> | |
| </main> | |
| <!-- Footer --> | |
| <footer class="w-full py-6 text-center text-slate-600 text-sm border-t border-slate-800/50 mt-auto"> | |
| <p>© 2023 Keep Going. Stay consistent.</p> | |
| </footer> | |
| <!-- Canvas for Confetti --> | |
| <div id="confetti-container" class="fixed inset-0 pointer-events-none z-[100] overflow-hidden"></div> | |
| <script> | |
| // --- Data & State --- | |
| const quotes = [ | |
| "Success is the sum of small efforts, repeated day in and day out.", | |
| "Don't watch the clock; do what it does. Keep going.", | |
| "The secret of getting ahead is getting started.", | |
| "It always seems impossible until it's done.", | |
| "Your future is created by what you do today, not tomorrow.", | |
| "Believe you can and you're halfway there." | |
| ]; | |
| const categories = { | |
| health: { color: 'text-emerald-400', bg: 'bg-emerald-500/10', border: 'border-emerald-500/20', icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />' }, | |
| work: { color: 'text-blue-400', bg: 'bg-blue-500/10', border: 'border-blue-500/20', icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2m4 6h.01M5 20h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />' }, | |
| learning: { color: 'text-amber-400', bg: 'bg-amber-500/10', border: 'border-amber-500/20', icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />' }, | |
| mindfulness: { color: 'text-purple-400', bg: 'bg-purple-500/10', border: 'border-purple-500/20', icon: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />' } | |
| }; | |
| let habits = [ | |
| { id: 1, title: "Morning Meditation", category: "mindfulness", completed: false, streak: 5 }, | |
| { id: 2, title: "Drink 2L Water", category: "health", completed: false, streak: 12 }, | |
| { id: 3, title: "Read 10 Pages", category: "learning", completed: true, streak: 3 }, | |
| { id: 4, title: "Deep Work Session", category: "work", completed: false, streak: 8 }, | |
| { id: 5, title: "Evening Walk", category: "health", completed: false, streak: 2 } | |
| ]; | |
| let currentFilter = 'all'; | |
| // --- DOM Elements --- | |
| const habitListEl = document.getElementById('habit-list'); | |
| const emptyStateEl = document.getElementById('empty-state'); | |
| const progressRing = document.getElementById('progress-ring'); | |
| const progressText = document.getElementById('progress-text'); | |
| const quoteEl = document.getElementById('motivational-quote'); | |
| const form = document.getElementById('add-habit-form'); | |
| const input = document.getElementById('new-habit-input'); | |
| const categorySelect = document.getElementById('new-habit-category'); | |
| const dateEl = document.getElementById('current-date'); | |
| const timeEl = document.getElementById('current-time'); | |
| // --- Initialization --- | |
| document.addEventListener('DOMContentLoaded', () => { | |
| updateTime(); | |
| setInterval(updateTime, 1000); | |
| renderHabits(); | |
| updateStats(); | |
| initBackgroundParticles(); | |
| // Random Quote | |
| quoteEl.textContent = `"${quotes[Math.floor(Math.random() * quotes.length)]}"`; | |
| }); | |
| // --- Core Functions --- | |
| function updateTime() { | |
| const now = new Date(); | |
| dateEl.textContent = now.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' }); | |
| timeEl.textContent = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); | |
| } | |
| function renderHabits() { | |
| habitListEl.innerHTML = ''; | |
| const filteredHabits = habits.filter(h => { | |
| if (currentFilter === 'active') return !h.completed; | |
| if (currentFilter === 'completed') return h.completed; | |
| return true; | |
| }); | |
| if (filteredHabits.length === 0) { | |
| emptyStateEl.classList.remove('hidden'); | |
| } else { | |
| emptyStateEl.classList.add('hidden'); | |
| filteredHabits.forEach(habit => { | |
| const style = categories[habit.category]; | |
| const el = document.createElement('div'); | |
| el.className = `habit-card glass-panel rounded-xl p-4 flex items-center justify-between border border-slate-700/50 ${habit.completed ? 'opacity-60' : ''}`; | |
| el.style.animation = 'slideIn 0.4s ease-out forwards'; | |
| el.innerHTML = ` | |
| <div class="flex items-center gap-4"> | |
| <div class="w-10 h-10 rounded-lg ${style.bg} ${style.color} flex items-center justify-center border ${style.border}"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| ${style.icon} | |
| </svg> | |
| </div> | |
| <div> | |
| <h4 class="font-medium text-white ${habit.completed ? 'line-through text-slate-500' : ''}">${habit.title}</h4> | |
| <div class="flex items-center gap-2 mt-1"> | |
| <span class="text-xs px-2 py-0.5 rounded-full bg-slate-800 text-slate-400 capitalize border border-slate-700">${habit.category}</span> | |
| <span class="text-xs text-orange-400 flex items-center gap-1"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" viewBox="0 0 20 20" fill="currentColor"> | |
| <path fill-rule="evenodd" d="M12.395 2.553a1 1 0 00-1.45-.385c-.345.23-.614.558-.822.88-.214.33-.403.713-.57 1.116-.334.804-.614 1.768-.84 2.734a31.365 31.365 0 00-.613 3.58 2.64 2.64 0 01-.945-1.067c-.328-.68-.398-1.534-.398-2.654A1 1 0 005.05 6.05 6.981 6.981 0 003 11a7 7 0 1011.95-4.95c-.592-.591-.98-.985-1.348-1.467-.363-.476-.724-1.063-1.207-2.03zM12.12 15.12A3 3 0 017 13s.879.5 2.5.5c0-1 .5-4 1.25-4.5.5 1 .786 1.293 1.371 1.879A2.99 2.99 0 0113 13a2.99 2.99 0 01-.879 2.121z" clip-rule="evenodd" /> | |
| </svg> | |
| ${habit.streak} day streak | |
| </span> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="flex items-center gap-3"> | |
| <button onclick="deleteHabit(${habit.id})" class="text-slate-600 hover:text-red-400 transition-colors p-2"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /> | |
| </svg> | |
| </button> | |
| <label class="checkbox-wrapper cursor-pointer relative w-8 h-8"> | |
| <input type="checkbox" class="appearance-none w-full h-full" ${habit.completed ? 'checked' : ''} onchange="toggleHabit(${habit.id})"> | |
| <div class="w-8 h-8 border-2 border-slate-600 rounded-lg flex items-center justify-center transition-all hover:border-indigo-400"> | |
| <svg class="w-5 h-5 text-white hidden pointer-events-none" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"></path></svg> | |
| </div> | |
| </label> | |
| </div> | |
| `; | |
| habitListEl.appendChild(el); | |
| }); | |
| } | |
| } | |
| function toggleHabit(id) { | |
| const habit = habits.find(h => h.id === id); | |
| if (habit) { | |
| habit.completed = !habit.completed; | |
| if (habit.completed) { | |
| habit.streak++; | |
| triggerConfetti(); | |
| } else { | |
| habit.streak--; | |
| } | |
| renderHabits(); | |
| updateStats(); | |
| } | |
| } | |
| function deleteHabit(id) { | |
| if(confirm('Delete this habit?')) { | |
| habits = habits.filter(h => h.id !== id); | |
| renderHabits(); | |
| updateStats(); | |
| } | |
| } | |
| function addHabit(e) { | |
| e.preventDefault(); | |
| const title = input.value.trim(); | |
| const category = categorySelect.value; | |
| if (title) { | |
| const newHabit = { | |
| id: Date.now(), | |
| title: title, | |
| category: category, | |
| completed: false, | |
| streak: 0 | |
| }; | |
| habits.unshift(newHabit); // Add to top | |
| input.value = ''; | |
| renderHabits(); | |
| updateStats(); | |
| } | |
| } | |
| form.addEventListener('submit', addHabit); | |
| function filterHabits(filter) { | |
| currentFilter = filter; | |
| // Update buttons | |
| document.querySelectorAll('.filter-btn').forEach(btn => { | |
| if (btn.textContent.toLowerCase() === filter) { | |
| btn.classList.remove('bg-slate-800', 'text-slate-400'); | |
| btn.classList.add('bg-indigo-600', 'text-white'); | |
| } else { | |
| btn.classList.add('bg-slate-800', 'text-slate-400'); | |
| btn.classList.remove('bg-indigo-600', 'text-white'); | |
| } | |
| }); | |
| renderHabits(); | |
| } | |
| function updateStats() { | |
| const total = habits.length; | |
| const completed = habits.filter(h => h.completed).length; | |
| const percent = total === 0 ? 0 : Math.round((completed / total) * 100); | |
| // Update Ring | |
| const radius = 40; | |
| const circumference = 2 * Math.PI * radius; | |
| const offset = circumference - (percent / 100) * circumference; | |
| progressRing.style.strokeDashoffset = offset; | |
| progressText.textContent = `${percent}%`; | |
| // Update Streak (Max streak of all habits) | |
| const maxStreak = habits.length > 0 ? Math.max(...habits.map(h => h.streak)) : 0; | |
| document.getElementById('streak-count').textContent = maxStreak; | |
| } | |
| // --- Visual Effects --- | |
| function triggerConfetti() { | |
| const colors = ['#4f46e5', '#ec4899', '#10b981', '#f59e0b']; | |
| const container = document.getElementById('confetti-container'); | |
| for (let i = 0; i < 50; i++) { | |
| const confetti = document.createElement('div'); | |
| confetti.className = 'confetti'; | |
| confetti.style.left = Math.random() * 100 + 'vw'; | |
| confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)]; | |
| confetti.style.animation = `confetti-fall ${Math.random() * 3 + 2}s linear forwards`; | |
| container.appendChild(confetti); | |
| // Cleanup | |
| setTimeout(() => { | |
| confetti.remove(); | |
| }, 5000); | |
| } | |
| } | |
| function initBackgroundParticles() { | |
| const canvas = document.getElementById('bgCanvas'); | |
| const ctx = canvas.getContext('2d'); | |
| let width, height; | |
| let particles = []; | |
| function resize() { | |
| width = canvas.width = window.innerWidth; | |
| height = canvas.height = window.innerHeight; | |
| } | |
| class Particle { | |
| constructor() { | |
| this.x = Math.random() * width; | |
| this.y = Math.random() * height; | |
| this.vx = (Math.random() - 0.5) * 0.5; | |
| this.vy = (Math.random() - 0.5) * 0.5; | |
| this.size = Math.random() * 2; | |
| this.color = `rgba(${Math.random() > 0.5 ? '99, 102, 241' : '236, 72, 153'}, ${Math.random() * 0.5})`; | |
| } | |
| update() { | |
| this.x += this.vx; | |
| this.y += this.vy; | |
| if (this.x < 0 || this.x > width) this.vx *= -1; | |
| if (this.y < 0 || this.y > height) this.vy *= -1; | |
| } | |
| draw() { | |
| ctx.fillStyle = this.color; | |
| ctx.beginPath(); | |
| ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2); | |
| ctx.fill(); | |
| } | |
| } | |
| function init() { | |
| particles = []; | |
| for (let i = 0; i < 50; i++) { | |
| particles.push(new Particle()); | |
| } | |
| } | |
| function animate() { | |
| ctx.clearRect(0, 0, width, height); | |
| particles.forEach(p => { | |
| p.update(); | |
| p.draw(); | |
| }); | |
| // Draw connections | |
| particles.forEach((p1, i) => { | |
| particles.slice(i + 1).forEach(p2 => { | |
| const dx = p1.x - p2.x; | |
| const dy = p1.y - p2.y; | |
| const dist = Math.sqrt(dx * dx + dy * dy); | |
| if (dist < 150) { | |
| ctx.strokeStyle = `rgba(148, 163, 184, ${0.1 - dist/1500})`; | |
| ctx.lineWidth = 1; | |
| ctx.beginPath(); | |
| ctx.moveTo(p1.x, p1.y); | |
| ctx.lineTo(p2.x, p2.y); | |
| ctx.stroke(); | |
| } | |
| }); | |
| }); | |
| requestAnimationFrame(animate); | |
| } | |
| window.addEventListener('resize', resize); | |
| resize(); | |
| init(); | |
| animate(); | |
| } | |
| </script> | |
| </body> | |
| </html> |