diff options
-rw-r--r-- | manifest.json | 2 | ||||
-rw-r--r-- | options.html | 20 | ||||
-rw-r--r-- | options.js | 42 | ||||
-rw-r--r-- | tempo.js | 6 |
4 files changed, 70 insertions, 0 deletions
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 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> + <link rel="stylesheet" type="text/css" href="fonts/lato.css" /> + <link rel="stylesheet" type="text/css" href="style.css" /> + <title>Tempo Options</title> + + <script type="text/javascript" src="options.js"></script> + </head> + <body> + <select id="timeformat"> + <option value="12">12-hour</option> + <option value="24">24-hour</option> + </select> + <br /> + <p id="status"></p> + <button id="save">Save</button> + </body> +</html> 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 <dvshakaryan@gmail.com> +// 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; @@ -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); |