// Shared JavaScript across all pages console.log('TimeTracker Pro - Work Hours Wizard loaded'); // Initialize app functionality document.addEventListener('DOMContentLoaded', function() { // Check for service worker support if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(registration => console.log('SW registered')) .catch(error => console.log('SW registration failed')); } // Handle mobile menu toggle const mobileMenuBtn = document.getElementById('mobile-menu-btn'); const mobileMenu = document.getElementById('mobile-menu'); if (mobileMenuBtn && mobileMenu) { mobileMenuBtn.addEventListener('click', function() { mobileMenu.classList.toggle('hidden'); }); } // Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // Theme handling const themeToggle = document.getElementById('theme-toggle'); if (themeToggle) { themeToggle.addEventListener('click', function() { const html = document.documentElement; if (html.classList.contains('dark')) { html.classList.remove('dark'); localStorage.setItem('theme', 'light'); } else { html.classList.add('dark'); localStorage.setItem('theme', 'dark'); } feather.replace(); }); } // Check for saved theme preference const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'dark') { document.documentElement.classList.add('dark'); } // Add loading states to buttons document.querySelectorAll('button, a').forEach(element => { element.addEventListener('click', function() { if (this.classList.contains('btn-loading')) { this.classList.add('loading'); const originalText = this.innerHTML; this.innerHTML = ' Loading...'; feather.replace(); // Reset after 2 seconds for demo setTimeout(() => { this.classList.remove('loading'); this.innerHTML = originalText; feather.replace(); }, 2000); } }); }); }); // API functions for time tracking const TimeTrackerAPI = { // Simulate time tracking data getCurrentTime: function() { return new Date().toLocaleTimeString(); }, // Calculate work duration calculateDuration: function(startTime, endTime) { const start = new Date(`1970-01-01T${startTime}`); const end = new Date(`1970-01-01T${endTime}`); const diff = end - start; const hours = Math.floor(diff / 3600000); const minutes = Math.floor((diff % 3600000) / 60000); return `${hours}h ${minutes}m`; }, // Get today's summary getTodaySummary: function() { return { totalHours: '8.5', tasksCompleted: 12, breaksTaken: 3, overtime: '0.5' }; } }; // Export for use in other modules window.TimeTrackerAPI = TimeTrackerAPI;