Permalink
Browse files

[master] Added regExp's to match user and favicon notification handler

  • Loading branch information...
1 parent 53d4b05 commit c409a289bb850bad8302f819a29b0c7185307a8f @alejandro alejandro committed Mar 18, 2012
Showing with 97 additions and 7 deletions.
  1. +3 −2 public/css/irc.css
  2. BIN public/favicon.ico
  3. +1 −0 public/index.html
  4. +84 −5 public/js/app.js
  5. +9 −0 public/js/tinycon.min.js
View
@@ -36,7 +36,7 @@ body {
}
.time {
text-align: right;
- color: #CCC;
+ color: #222;
margin-right: 0;
float: right;
}
@@ -219,5 +219,6 @@ a {
clear: both;
height: 2em;
}
-
+.gold {background-color:#FFD700 !important;}
+.me .time {color:#222 !important;}
.off {display: none;}
View
Binary file not shown.
View
@@ -48,6 +48,7 @@
<script src="//code.jquery.com/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/spin.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
+ <script type="text/javascript" src="/js/tinycon.min.js"></script>
<script src="/js/app.js" type="text/javascript"></script>
</div>
</body>
View
@@ -12,6 +12,7 @@ $(document).ready(function(){
var sendMsg = $('#sendMessage')
var chatBody = $('#chat_body');
var nick_ul = $('#nick_ul');
+ window.counter = 0;
var get = function(el){
return document.getElementById(el);
}
@@ -43,15 +44,19 @@ $(document).ready(function(){
meta.name = 'nick';
var head = document.getElementsByTagName('head')[0];
head.appendChild(meta);
+ window.nick = $('[name="nick"]').attr('content');
statusMsg.text(' Joining as '+nick+'...' )
- sock = io.connect('http://ircbeta.nodester.com/');
+ sock = io.connect('http://'+window.location.host);
sock.on('message', handleMessage);
sock.send(JSON.stringify({ nickname: nick }));
$('#chat_wrapper').removeClass('off');
});
-
+ window.onfocus =function(){
+ Tinycon.setBubble(0);
+ counter = 0;
+ };
window.getNickname = function (name) {
- var name = name || $('[name="nick"]').attr('content') || 'Guest' + parseInt(Math.random(0,10)*15);
+ var name = name || nick || 'Guest' + parseInt(Math.random(0,10)*15);
switch (name) {
case "":
alert("You did not input a nickname, please reload if you wish to connect.");
@@ -75,9 +80,22 @@ $(document).ready(function(){
} else {
row.className = 'btn'
}
+ var style=''
+ var row_class =''
+ if (nick){
+ var reg = nick.replace(/\s+/, "|");
+ var regexp = new RegExp(reg,'gi');
+ if (regexp.test(message)){
+ Tinycon.setBubble(++counter);
+ row_class='gold'
+ } else {
+ row_class='default'
+ }
+ message = giveMeColors(message);
+ }
row.innerHTML = ''
+ '<th class="author">' + from + '</th>'
- + '<td class="msg">' + message.replace(/\[[0-9][0-9]m/g,'') +'<span class="time">'+ (new Date()).toTimeString().substr(0,9)+'</td>';
+ + '<td class="msg '+row_class+'">' + message.replace(/\[[0-9][0-9]m/g,'') +'<span class="time">'+ (new Date()).toTimeString().substr(0,9)+'</td>';
chatBody.append(row);
scrollBody();
};
@@ -133,7 +151,6 @@ $(document).ready(function(){
rv = sock.send(JSON.stringify({ nickname: nickname }));
}
} else {
- console.log(typeof obj, typeof data)
if (obj && obj.messagetype) {
var s = (obj.from == nickname) ? true : false;
switch (obj.messagetype) {
@@ -194,5 +211,67 @@ $(document).ready(function(){
return r.toString();
});
}
+ var ocolors = {
+ 'bold' : ['\033[1m', '\033[22m'],
+ 'italic' : ['\033[3m', '\033[23m'],
+ 'underline' : ['\033[4m', '\033[24m'],
+ 'inverse' : ['\033[7m', '\033[27m'],
+ 'white' : ['\033[37m', '\033[39m'],
+ 'grey' : ['\033[90m', '\033[39m'],
+ 'black' : ['\033[30m', '\033[39m'],
+ 'blue' : ['\033[34m', '\033[39m'],
+ 'cyan' : ['\033[36m', '\033[39m'],
+ 'green' : ['\033[32m', '\033[39m'],
+ 'magenta' : ['\033[35m', '\033[39m'],
+ 'red' : ['\033[31m', '\033[39m'],
+ 'yellow' : ['\033[33m', '\033[39m']
+ }
+ var colors = {
+ 'p':['<p>','</p>'],
+ '[1m' :['<strong>','</strong>'],
+ '[22m' :['<strong>','</strong>'],
+ '[3m' :['<i>','</i>'],
+ '[23m' :['<i>','</i>'],
+ '[4m' :['<u>','</u>'],
+ '[24m' :['<u>','</u>'],
+ '[7m' :['<span>','</span>'],
+ '[27m' :['<span>','</span>'],
+ '[37m' :['<span style="color:white">','</span>'],
+ '[90m' :['<span style="color:grey">','</span>'],
+ '[30m' :['<span style="color:#444">','</span>'],
+ '[34m' :['<span style="color:blue">','</span>'],
+ '[36m' :['<span style="color:cyan">','</span>'],
+ '[32m' :['<span style="color:green">','</span>'],
+ '[35m' :['<span style="color:magenta">','</span>'],
+ '[31m' :['<span style="color:red">','</span>'],
+ '[33m' :['<span style="color:yellow">','</span>']
+ }
+ var giveMeColors = function(str){
+ var old = str = str ||'[44m'+str+'[43m';
+ str = str.split(str.search(/\[[0-9][0-9]m/));
+ var text = str.join('').split(/\[[0-9][0-9]m/g);
+ var color = str.join('').match(/\[[0-9][0-9]m|\[[0-9]m/g)||'';
+ var loop = -1;
+ var dohs = 0;
+ while (color[loop + 1]){
+ var prev = ++loop;
+ var next = ++loop;
+ if (color[prev]){
+ if (colors[color[prev]]){
+ var math = (old.search('\\'+color[next])-old.search('\\'+color[prev]))
+ if (!(math > 0 && math < 5)){
+ old = old.replace(new RegExp('\\'+color[prev]), colors[color[prev]][0])
+ old = old.replace(new RegExp('\\'+color[next]),colors[color[prev]][1]);
+ } else {
+ old = old.replace(new RegExp('\\'+color[prev]), colors[color[prev]][0])
+ old = old.replace(new RegExp('\\'+color[next]), colors[color[next]][0])
+ old = old.replace(new RegExp('\\'+color[++loop]), colors[color[next]][1])
+ old = old.replace(new RegExp('\\'+color[++loop]),colors[color[prev]][1]);
+ }
+ }
+ }
+ }
+ return old.replace(/\[[0-9]m|\[|[0-9][0-9]m|/g,'');
+ }
});
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit c409a28

Please sign in to comment.