function calculateTotalTime(section) { const times = [ { id: 'time-1m', minutes: 1 }, { id: 'time-3m', minutes: 3 }, { id: 'time-5m', minutes: 5 }, { id: 'time-10m', minutes: 10 }, { id: 'time-15m', minutes: 15 }, { id: 'time-30m', minutes: 30 }, { id: 'time-60m', minutes: 60 }, { id: 'time-3h', minutes: 180 }, { id: 'time-8h', minutes: 480 }, { id: 'time-15h', minutes: 900 }, { id: 'time-24h', minutes: 1440 }, { id: 'time-3d', minutes: 4320 }, { id: 'time-7d', minutes: 10080 }, { id: 'time-30d', minutes: 43200 }, ]; let totalMinutes = 0; times.forEach(time => { const input = document.getElementById(`${time.id}-${section}`); if (input && input.value) { const value = parseInt(input.value); if (!isNaN(value)) { totalMinutes += time.minutes * value; } } }); updateResults(section, totalMinutes); return totalMinutes; } function updateResults(section, totalMinutes) { const totalSeconds = totalMinutes * 60; const totalHours = totalMinutes / 60; const totalDays = totalHours / 24; document.getElementById(`total-seconds-${section}`).textContent = formatTime(totalSeconds); document.getElementById(`total-minutes-${section}`).textContent = `${totalMinutes.toFixed(2).replace(/\.00$/, '')} min`; document.getElementById(`total-hours-${section}`).textContent = `${totalHours.toFixed(2).replace(/\.00$/, '')} h`; document.getElementById(`total-days-${section}`).textContent = `${totalDays.toFixed(2).replace(/\.00$/, '')} d`; } function formatTime(seconds) { const days = Math.floor(seconds / (24 * 3600)); const hours = Math.floor((seconds % (24 * 3600)) / 3600); const minutes = Math.floor((seconds % 3600) / 60); return `${days} d ${hours} h ${minutes} min`; } function calculateSummary() { const universalMinutes = calculateTotalTime('universal'); const totalMinutes = ['building', 'research', 'training', 'healing'] .map(section => calculateTotalTime(section)) .reduce((a, b) => a + b, universalMinutes); const totalSeconds = totalMinutes * 60; document.getElementById('summary-total').textContent = formatTime(totalSeconds); const summaries = { 'building-universal': calculateTotalTime('building') + universalMinutes, 'research-universal': calculateTotalTime('research') + universalMinutes, 'training-universal': calculateTotalTime('training') + universalMinutes, 'healing-universal': calculateTotalTime('healing') + universalMinutes, }; Object.keys(summaries).forEach(key => { const totalSecondsSummary = summaries[key] * 60; document.getElementById(`summary-${key}`).textContent = formatTime(totalSecondsSummary); }); } function resetSection(section) { const inputs = document.querySelectorAll(`#${section} input`); inputs.forEach(input => (input.value = '')); const resultElements = document.querySelectorAll(`#${section} .result span`); resultElements.forEach(result => (result.textContent = '0')); calculateTotalTime(section); calculateSummary(); } function resetAllSections() { ['building', 'research', 'training', 'healing', 'universal'].forEach(section => { resetSection(section); }); document.getElementById('summary-total').textContent = '0 d 0 h 0 min'; ['building-universal', 'research-universal', 'training-universal', 'healing-universal'].forEach(key => { document.getElementById(`summary-${key}`).textContent = '0 d 0 h 0 min'; }); } window.onload = () => { ['building', 'research', 'training', 'healing', 'universal'].forEach(section => { calculateTotalTime(section); }); calculateSummary(); document.querySelectorAll('.speedup-group input').forEach(input => { input.addEventListener('input', () => { const section = input.closest('.speedup-group').id; calculateTotalTime(section); calculateSummary(); }); }); };