diff options
Diffstat (limited to 'webchat/public/client.js')
| -rw-r--r-- | webchat/public/client.js | 34 | 
1 files changed, 32 insertions, 2 deletions
| diff --git a/webchat/public/client.js b/webchat/public/client.js index 95b67ad0..ca71b537 100644 --- a/webchat/public/client.js +++ b/webchat/public/client.js @@ -6,9 +6,36 @@ function setMaybeNick (input) {    var match = /^\/nick\s+(.+)$/.exec(input);    if (match) {      nick = match[1]; +    $('#nick').html(nick);    }  } +function getCurTime () { +  date = new Date; +  h = date.getHours(); +  if(h<10) +  { +    h = "0"+h; +  } +  m = date.getMinutes(); +  if(m<10) +  { +    m = "0"+m; +  } +  s = date.getSeconds(); +  if(s<10) +  { +    s = "0"+s; +  } +  return ''+h+':'+m+':'+s; +}; + +$(function updateTime () { +  $('#time').html(getCurTime()); +  setTimeout(updateTime,'1000'); +  return true; +}); +  var nick;  $(function connect() { @@ -25,8 +52,11 @@ $(function connect() {        console.log(object.message);        var safe_message = $('<div/>').text(object.message).html();        safe_message = replaceURLWithHTMLLinks(safe_message); -  var safe_from = $('<div/>').text(object.from).html(); -  $('#chatbox').append('<tr><td class="chat_from">'+safe_from+'</td><td class="chat_msg">'+safe_message+'</td></tr>'); +      var safe_from = $('<div/>').text(object.from).html(); +      $('<tr><td class="chat_date">'+getCurTime()+'</td><td class="chat_from">'+safe_from+'</td><td class="chat_msg">'+safe_message+'</td></tr>').insertBefore('#foot'); + +      var elem = document.getElementById('chatter'); +      elem.scrollTop = elem.scrollHeight;      } catch (error) {        console.log(error); | 
