From eabbe53c13e5fcf45a50b2163c871e6f9d55f991 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 26 Feb 2014 13:11:45 -0800 Subject: Add option for 12-hour time. --- manifest.json | 2 ++ options.html | 20 ++++++++++++++++++++ options.js | 42 ++++++++++++++++++++++++++++++++++++++++++ tempo.js | 6 ++++++ 4 files changed, 70 insertions(+) create mode 100644 options.html create mode 100644 options.js diff --git a/manifest.json b/manifest.json index 551cbc7..9eca683 100644 --- a/manifest.json +++ b/manifest.json @@ -11,6 +11,8 @@ "128": "icon/clock128.png" }, + "options_page": "options.html", + "chrome_url_overrides": { "newtab": "index.html" } diff --git a/options.html b/options.html new file mode 100644 index 0000000..52f7b3e --- /dev/null +++ b/options.html @@ -0,0 +1,20 @@ + + + + + + + Tempo Options + + + + + +
+

+ + + diff --git a/options.js b/options.js new file mode 100644 index 0000000..b8986ae --- /dev/null +++ b/options.js @@ -0,0 +1,42 @@ +// 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 save_options() { + var select = document.getElementById('timeformat'); + var timeformat = select.children[select.selectedIndex].value; + localStorage['timeformat'] = timeformat; + + var status = document.getElementById('status'); + status.innerHTML = 'Options saved.'; + + setTimeout(function() {status.innerHTML = ''}, 1000); +} + +function restore_options() { + var timeformat = localStorage['timeformat']; + + if(!timeformat) { + return; + } + + var select = document.getElementById('timeformat'); + + for(var i = 0; i < select.children.length; i++) { + var child = select.children[i]; + + if(child.value == timeformat) { + child.selected = 'true'; + + break; + } + } +} + +function start_options() { + restore_options(); + + document.querySelector('#save').addEventListener('click', save_options); +} + +window.onload = start_options; diff --git a/tempo.js b/tempo.js index 6fed6ad..0d90f5f 100644 --- a/tempo.js +++ b/tempo.js @@ -13,6 +13,8 @@ function padTime(x) { } function updateTime() { + var timeformat = localStorage['timeformat']; + var date = new Date(); var h = date.getHours(); @@ -25,6 +27,10 @@ function updateTime() { var str_d = dd + " " + months[dm] + " " + dy; + if(timeformat == '12') { + h = (h + 11) % 12 + 1; + } + document.getElementById("h").innerHTML = padTime(h); document.getElementById("m").innerHTML = padTime(m); document.getElementById("s").innerHTML = padTime(s); -- cgit v1.2.3-70-g09d2