From a9358b6ffad0ac98a4e60f43beda24a22bc0224d Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 10 Apr 2022 03:26:28 -0700 Subject: refactor and make Firefox-friendly --- options.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'options.js') diff --git a/options.js b/options.js index 0c640b4..205cc2e 100644 --- a/options.js +++ b/options.js @@ -1,29 +1,24 @@ -// Copyright 2014 David Vazgenovich Shakaryan -// Distributed under the terms of the GNU General Public License v2. -// See http://www.gnu.org/licenses/gpl-2.0.txt for the full license text. - function saveOptions() { - var timeformat = 24; - if(document.getElementById('t12').checked) { - var timeformat = 12; - } + var timeformat; + if (document.getElementById('t24').checked) + timeformat = 24; + else if (document.getElementById('t12').checked) + timeformat = 12; + else + return; localStorage['timeformat'] = timeformat; var status = document.getElementById('status'); - status.style['visibility'] = 'visible'; - - setTimeout(function() {status.style['visibility'] = 'hidden'}, 2000); + status.innerHTML = 'Options saved'; + setTimeout(function() { status.innerHTML = '' }, 2000); } function restoreOptions() { - var timeformat = localStorage['timeformat']; - - if(!timeformat) { - timeformat = 24; - } - - var option = document.getElementById('t' + timeformat); + // default to 24 for both unset and invalid + var timeformat = localStorage['timeformat'] || 24; + var option = document.getElementById('t' + timeformat) || + document.getElementById('t24'); option.checked = true; } -- cgit v1.2.3-70-g09d2