diff options
Diffstat (limited to 'options.js')
-rw-r--r-- | options.js | 28 |
1 files changed, 17 insertions, 11 deletions
@@ -1,32 +1,38 @@ function saveOptions() { - var timeformat; + let timefmt; if (document.getElementById('t24').checked) - timeformat = 24; + timefmt = 24; else if (document.getElementById('t12').checked) - timeformat = 12; - else - return; + timefmt = 12; + localStorage['timefmt'] = timefmt; - localStorage['timeformat'] = timeformat; + localStorage['fg'] = document.getElementById('fg').value; + localStorage['bg'] = document.getElementById('bg').value; - var status = document.getElementById('status'); + let status = document.getElementById('status'); status.innerHTML = 'Options saved'; setTimeout(function() { status.innerHTML = '' }, 2000); } function restoreOptions() { // default to 24 for both unset and invalid - var timeformat = localStorage['timeformat'] || 24; - var option = document.getElementById('t' + timeformat) || + let timefmt = localStorage['timefmt'] || 24; + let timefmt_btn = document.getElementById('t' + timefmt) || document.getElementById('t24'); + timefmt_btn.checked = true; - option.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.querySelector('#save').addEventListener('click', saveOptions); + document.getElementById('save').addEventListener('click', saveOptions); } window.onload = startOptions; |