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['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 timefmt = localStorage['timefmt'] || 24; let timefmt_btn = document.getElementById('t' + timefmt) || document.getElementById('t24'); timefmt_btn.checked = true; let fg = localStorage['fg']; if (fg) document.getElementById('fg').value = fg; let bg = localStorage['bg']; if (bg) document.getElementById('bg').value = bg; } function startOptions() { restoreOptions(); document.getElementById('save').addEventListener('click', saveOptions); } window.onload = startOptions;