Spaces:
Running
Running
File size: 1,828 Bytes
2140345 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | // 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 = '<tr><td colspan="6" class="py-4 text-center text-gray-400">No recent calculations found</td></tr>';
return;
}
tableBody.innerHTML = calculations.slice(0, 5).map(calc => `
<tr class="border-b border-slate-700 hover:bg-slate-700 transition-colors">
<td class="py-3">${calc.date}</td>
<td>${calc.type.charAt(0).toUpperCase() + calc.type.slice(1)}</td>
<td>${calc.flowRate} m³/h</td>
<td>${calc.head} m</td>
<td>${calc.efficiency}</td>
<td>
<a href="calculator.html" class="text-primary hover:text-red-400 transition-colors">
<i data-feather="repeat" class="w-4 h-4"></i>
</a>
</td>
</tr>
`).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}`;
} |