Spaces:
Running
Running
| // Main application functionality for LifeTracker Pro | |
| class ActivityTracker { | |
| constructor() { | |
| this.activities = { | |
| sleep: { hours: 0, minutes: 0 }, | |
| work: { hours: 0, minutes: 0 }, | |
| play: { hours: 0, minutes: 0 }, | |
| exercise: { hours: 0, minutes: 0 } | |
| }; | |
| this.initializeEventListeners(); | |
| } | |
| initializeEventListeners() { | |
| // Add event listeners for activity buttons | |
| document.querySelectorAll('[class*="bg-"]:not(#reset-workout)').forEach(button => { | |
| button.addEventListener('click', (e) => { | |
| const activity = e.target.closest('.bg-white').querySelector('h3').textContent.toLowerCase(); | |
| this.logActivity(activity); | |
| }); | |
| }); | |
| } | |
| logActivity(activity) { | |
| // Simulate adding time (in a real app, this would open a modal or form) | |
| const randomHours = Math.floor(Math.random() * 3); | |
| const randomMinutes = Math.floor(Math.random() * 60); | |
| this.activities[activity] = { | |
| hours: this.activities[activity].hours + randomHours, | |
| minutes: this.activities[activity].minutes + randomMinutes | |
| }; | |
| // Normalize minutes to hours if over 60 | |
| if (this.activities[activity].minutes >= 60) { | |
| this.activities[activity].hours += Math.floor(this.activities[activity].minutes / 60); | |
| this.activities[activity].minutes = this.activities[activity].minutes % 60; | |
| } | |
| this.updateActivityDisplay(activity); | |
| } | |
| updateActivityDisplay(activity) { | |
| const activityElement = document.querySelector(`.bg-white:has(h3:contains("${activity.charAt(0).toUpperCase() + activity.slice(1)}"))`); | |
| const timeDisplay = activityElement.querySelector('.text-3xl'); | |
| const progressBar = activityElement.querySelector('.h-2:last-child'); | |
| const totalMinutes = (this.activities[activity].hours * 60) + this.activities[activity].minutes; | |
| const percentage = Math.min((totalMinutes / (8 * 60)) * 100, 100); // Cap at 8 hours equivalent | |
| timeDisplay.textContent = `${this.activities[activity].hours}h ${this.activities[activity].minutes}m`; | |
| progressBar.style.width = `${percentage}%`; | |
| } | |
| } | |
| class WorkoutTracker { | |
| constructor() { | |
| this.workoutItems = [ | |
| { id: 1, name: "150 stretching exercise", completed: false }, | |
| { id: 2, name: "150 push ups", completed: false }, | |
| { id: 3, name: "150 sit ups", completed: false }, | |
| { id: 4, name: "150 squats", completed: false }, | |
| { id: 5, name: "150 curls", completed: false }, | |
| { id: 6, name: "150 inclined push ups", completed: false }, | |
| { id: 7, name: "150 declined push ups", completed: false }, | |
| { id: 8, name: "200 gripping (each hand)", completed: false }, | |
| { id: 9, name: "Do at least minimum of 30 to 40 min mewing", completed: false }, | |
| { id: 10, name: "5 kilometres running", completed: false } | |
| ]; | |
| this.initializeWorkoutListeners(); | |
| } | |
| initializeWorkoutListeners() { | |
| document.getElementById('reset-workout').addEventListener('click', () => { | |
| this.resetWorkout(); | |
| }); | |
| } | |
| updateProgress() { | |
| const completed = this.workoutItems.filter(item => item.completed).length; | |
| const total = this.workoutItems.length; | |
| const percentage = Math.round((completed / total) * 100); | |
| document.getElementById('completion-percentage').textContent = `${percentage}%`; | |
| } | |
| resetWorkout() { | |
| this.workoutItems.forEach(item => { | |
| item.completed = false; | |
| }); | |
| this.renderChecklist(); | |
| this.updateProgress(); | |
| } | |
| renderChecklist() { | |
| const checklist = document.getElementById('workout-checklist'); | |
| checklist.innerHTML = ''; | |
| this.workoutItems.forEach(item => { | |
| const div = document.createElement('div'); | |
| div.className = 'flex items-center p-3 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors'; | |
| const checkbox = document.createElement('div'); | |
| checkbox.className = `workout-checkbox mr-3 ${item.completed ? 'checked' : ''}`; | |
| checkbox.addEventListener('click', () => { | |
| item.completed = !item.completed; | |
| checkbox.classList.toggle('checked'); | |
| this.updateProgress(); | |
| }); | |
| const label = document.createElement('span'); | |
| label.className = 'text-gray-800'; | |
| label.textContent = item.name; | |
| div.appendChild(checkbox); | |
| div.appendChild(label); | |
| checklist.appendChild(div); | |
| }); | |
| } | |
| } | |
| // Initialize the application | |
| function initializeApp() { | |
| window.activityTracker = new ActivityTracker(); | |
| window.workoutTracker = new WorkoutTracker(); | |
| } | |
| function initializeWorkoutChecklist() { | |
| window.workoutTracker = new WorkoutTracker(); | |
| window.workoutTracker.renderChecklist(); | |
| } | |
| // Initialize when DOM is loaded | |
| document.addEventListener('DOMContentLoaded', initializeApp); |