function saveOptions() { let timefmt; if (document.getElementById('t24').checked) timefmt = 24; else if (document.getElementById('t12').checked) timefmt = 12; localStorage['timefmt'] = timefmt; localStorage['fg'] = document.getElementById('fg').value; localStorage['fg_date'] = document.getElementById('fg_date').value; localStorage['bg'] = document.getElementById('bg').value; let status = document.getElementById('status'); status.textContent = 'Options saved'; setTimeout(function() { status.textContent = '' }, 2000); } function restoreOptions() { // default to 24 for both unset and invalid let val = localStorage['timefmt'] || 24; let btn = document.getElementById('t' + val) || document.getElementById('t24'); btn.checked = true; if ((val = localStorage['fg'])) document.getElementById('fg').value = val; if ((val = localStorage['fg_date'])) document.getElementById('fg_date').value = val; if ((val = localStorage['bg'])) document.getElementById('bg').value = val; } function startOptions() { restoreOptions(); document.getElementById('save').addEventListener('click', saveOptions); } window.onload = startOptions;