diff --git a/client/dcwebui.js b/client/dcwebui.js index 7e99de5..15fa0bc 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -118,6 +118,23 @@ function getOffsetTop( elem ) { return offsetTop; } +/* */ + +var date_format = function(d, format) { + var pad = function(s) { + return (s < 10) ? '0'+s : ''+s ; + }; + + var ret = format; + ret = ret.replace(/H/g, pad(d.getHours())); + ret = ret.replace(/i/g, pad(d.getMinutes())); + ret = ret.replace(/s/g, pad(d.getSeconds())); + ret = ret.replace(/Y/g, d.getFullYear()); + ret = ret.replace(/m/g, pad(d.getMonth() + 1)); + ret = ret.replace(/d/g, pad(d.getDate())); + return ret; +}; + /* Tab writers */ var write = function(tab) { @@ -140,14 +157,8 @@ var write = function(tab) { }, 'time': function() { var d = new Date(); - var pad = function(s) { - return (s < 10) ? '0'+s : ''+s ; - }; - return this.raw( - '['+ - pad(d.getHours()) + ":" + pad(d.getMinutes())+ - "] " - ); + + return this.raw('['+ date_format(new Date(), timestamp_formats[timestamp_format_index])+"] "); }, 'system': function(s) { return this.time().c('tx-sys', sanitise(s)).raw('
'); @@ -575,7 +586,8 @@ var menu = new MenuList($("#menubutton")); menu.reset = function() { this.clear(); - this.add(joinparts_getstr(), toggle_joinparts); + this.add(joinparts_getstr(), toggle_joinparts); + this.add(timestamp_display(), timestamp_toggle); }; var usermenu = new MenuList(document.body); @@ -692,6 +704,21 @@ var STATE_ACTIVE = 2; var chat_scrollback = []; var chat_scrollback_index = -1; +var timestamp_formats = [ "H:i", "H:i:s", "Y-m-d H:i:s" ]; +var timestamp_names = [ "Minutes", "Seconds", "Full" ]; +var timestamp_format_index = 0; + +var timestamp_display = function() { + return "Timestamp format: " + timestamp_names[timestamp_format_index]; +}; + +var timestamp_toggle = function(ev) { + var $el = ev.target || ev.srcElement; + timestamp_format_index = (timestamp_format_index + 1) % timestamp_formats.length; + persistence_set("timestamps", timestamp_format_index); + $el.innerHTML = timestamp_display(); +}; + var scrollback_move = function(delta) { if (chat_scrollback.length === 0) { return; // no effect @@ -817,6 +844,8 @@ window.onload = function() { usermenu.hide(); }; + timestamp_format_index = persistence_get("timestamps", 0); + menu.reset(); tab_addHandlers();