// Shared functions across the application // Load recent calculations on homepage document.addEventListener('DOMContentLoaded', function() { if (document.getElementById('recentCalculations')) { loadRecentCalculations(); } }); function loadRecentCalculations() { const calculations = JSON.parse(localStorage.getItem('pumpCalculations') || '[]'); const tableBody = document.getElementById('recentCalculations'); if (calculations.length === 0) { tableBody.innerHTML = 'No recent calculations found'; return; } tableBody.innerHTML = calculations.slice(0, 5).map(calc => ` ${calc.date} ${calc.type.charAt(0).toUpperCase() + calc.type.slice(1)} ${calc.flowRate} m³/h ${calc.head} m ${calc.efficiency} `).join(''); feather.replace(); } // Theme toggle functionality function toggleDarkMode() { const html = document.documentElement; html.classList.toggle('dark'); localStorage.setItem('darkMode', html.classList.contains('dark')); } // Check for saved theme preference if (localStorage.getItem('darkMode') === 'false') { document.documentElement.classList.remove('dark'); } // Format numbers with units function formatNumber(value, unit) { if (isNaN(value)) return '-'; return `${parseFloat(value.toFixed(2))} ${unit}`; }