function inputParser (str) { var match = /^\/([a-z]+)(?:\s+(.*\S))?\s*$/.exec(str) if (match) { return { method: match[1], params: match[2] } } else { return { method: 'say', params: str } } } function clientParser(object) { console.log(object) switch (object.type) { case 'message': return printMessage(object); case 'join': return handleJoin(object); case 'quit': return handleQuit(object); case 'nicklist': return handleNicklist(object); case 'nickchange': return handleNickchange(object); } }; function handleJoin(object) { var safe_from = $('
').text(object.from).html(); $(''+getCurTime()+''+safe_from+'joined').insertBefore('#foot'); $('#nicklist').append('
' + safe_from + '
') ; }; function handleQuit(object) { var safe_from = $('
').text(object.from).html(); $(''+getCurTime()+''+safe_from+'quit').insertBefore('#foot'); console.log('removing', safe_from); $(getNicklistElement(safe_from)).remove(); }; function handleNicklist(object) { Object.keys(object.message).forEach(function (nick) { // console.log('nick',nick); var hash_from = btoa(nick).replace(/=/g,'_'); // $('.name').each(function (i,e) { console.log(i,e); if (e.innerHTML === 'kweb') { $(e).attr("style", "color:green") } }) $('#nicklist').append('
' + nick + '
') ; }); }; function handleNickchange(object) { var safe_from = $('
').text(object.nick).html(); var safe_newnick = $('
').text(object.newnick).html(); $(''+getCurTime()+''+safe_from+'is now known as '+object.newnick+'').insertBefore('#foot'); $(getNicklistElement(safe_from)).remove(); $('#nicklist').append('
' + safe_from + '
') ; }; function replaceURLWithHTMLLinks (text) { var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; return text.replace(exp,"$1"); } function setMaybeNick (input) { if (match) { nick = match[1]; $('#nick').html(nick); } } function sortNicklist () { }; function getNicklistElement(name) { var el; $('.name').each(function (i,e) { if (e.innerHTML === name) { if (typeof el !== 'undefined') { throw new Error('duplicate name: ' + name); }; el = e; }; }); return el; } function chatboxAppend (chat_from, chat_msg, type) { type = type||'chat' $(''+getCurTime()+''+chat_from+''+chat_msg+'').insertBefore('#foot'); var elem = document.getElementById('chatter'); elem.scrollTop = elem.scrollHeight; }; function printMessage(object) { var safe_message = $('
').text(object.message).html(); safe_message = replaceURLWithHTMLLinks(safe_message); var safe_from = $('
').text(object.nick).html(); return chatboxAppend(safe_from, safe_message) }; 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; };