laurentgiovani2
laurentgiovani2
laurentgiovani2
1 post
Don't wanna be here? Send us removal request.
laurentgiovani2 · 8 months ago
Text
Off Working Rest
Current State: OFF
Today's Statistics
Working Time: 0h 0m 0s
Rest Time: 0h 0m 0s
#time-tracker-app { font-family: Arial, sans-serif; max-width: 300px; margin: 0 auto; padding: 20px; text-align: center; } button { padding: 10px; margin: 5px; border: none; color: white; font-weight: bold; cursor: pointer; } #off-button { background-color: grey; } #working-button { background-color: red; } #rest-button { background-color: blue; } .active { opacity: 0.7; } #state-text { margin-top: 20px; font-size: 18px; } #stats { margin-top: 30px; text-align: left; } var appState = 'OFF'; var startTime = null; function handleStateChange(newState) { if (appState !== 'OFF' && newState !== 'OFF') { saveTimeSpent(); } appState = newState; startTime = newState !== 'OFF' ? new Date().getTime() : null; updateUI(); localStorage.setItem('appState', appState); } function updateUI() { document.getElementById('state-text').innerHTML = 'Current State: ' + appState; document.getElementById('off-button').className = appState === 'OFF' ? 'active' : ''; document.getElementById('working-button').className = appState === 'WORKING' ? 'active' : ''; document.getElementById('rest-button').className = appState === 'REST' ? 'active' : ''; } function saveTimeSpent() { if (startTime) { var endTime = new Date().getTime(); var duration = endTime - startTime; var key = appState.toLowerCase() + '_' + new Date().toISOString().split('T')[0]; var existingTime = localStorage.getItem(key) || '0'; var newTime = parseInt(existingTime) + duration; localStorage.setItem(key, newTime.toString()); updateStats(); } } function updateStats() { var today = new Date().toISOString().split('T')[0]; var workingTime = parseInt(localStorage.getItem('working_' + today) || '0'); var restTime = parseInt(localStorage.getItem('rest_' + today) || '0'); document.getElementById('working-time').innerHTML = 'Working Time: ' + formatTime(workingTime); document.getElementById('rest-time').innerHTML = 'Rest Time: ' + formatTime(restTime); } function formatTime(ms) { var seconds = Math.floor(ms / 1000); var minutes = Math.floor(seconds / 60); var hours = Math.floor(minutes / 60); return hours + 'h ' + (minutes % 60) + 'm ' + (seconds % 60) + 's'; } document.getElementById('off-button').onclick = function() { handleStateChange('OFF'); }; document.getElementById('working-button').onclick = function() { handleStateChange('WORKING'); }; document.getElementById('rest-button').onclick = function() { handleStateChange('REST'); }; var savedState = localStorage.getItem('appState'); if (savedState) { appState = savedState; updateUI(); } updateStats(); setInterval(updateStats, 1000);
1 note · View note