Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit c409a289bb850bad8302f819a29b0c7185307a8f 1 parent 53d4b05
Alejandro Morales alejandro authored
5 public/css/irc.css
@@ -36,7 +36,7 @@ body {
36 36 }
37 37 .time {
38 38 text-align: right;
39   - color: #CCC;
  39 + color: #222;
40 40 margin-right: 0;
41 41 float: right;
42 42 }
@@ -219,5 +219,6 @@ a {
219 219 clear: both;
220 220 height: 2em;
221 221 }
222   -
  222 +.gold {background-color:#FFD700 !important;}
  223 +.me .time {color:#222 !important;}
223 224 .off {display: none;}
BIN  public/favicon.ico
Binary file not shown
1  public/index.html
@@ -48,6 +48,7 @@
48 48 <script src="//code.jquery.com/jquery.js" type="text/javascript"></script>
49 49 <script type="text/javascript" src="/js/spin.min.js"></script>
50 50 <script src="/socket.io/socket.io.js"></script>
  51 + <script type="text/javascript" src="/js/tinycon.min.js"></script>
51 52 <script src="/js/app.js" type="text/javascript"></script>
52 53 </div>
53 54 </body>
89 public/js/app.js
@@ -12,6 +12,7 @@ $(document).ready(function(){
12 12 var sendMsg = $('#sendMessage')
13 13 var chatBody = $('#chat_body');
14 14 var nick_ul = $('#nick_ul');
  15 + window.counter = 0;
15 16 var get = function(el){
16 17 return document.getElementById(el);
17 18 }
@@ -43,15 +44,19 @@ $(document).ready(function(){
43 44 meta.name = 'nick';
44 45 var head = document.getElementsByTagName('head')[0];
45 46 head.appendChild(meta);
  47 + window.nick = $('[name="nick"]').attr('content');
46 48 statusMsg.text(' Joining as '+nick+'...' )
47   - sock = io.connect('http://ircbeta.nodester.com/');
  49 + sock = io.connect('http://'+window.location.host);
48 50 sock.on('message', handleMessage);
49 51 sock.send(JSON.stringify({ nickname: nick }));
50 52 $('#chat_wrapper').removeClass('off');
51 53 });
52   -
  54 + window.onfocus =function(){
  55 + Tinycon.setBubble(0);
  56 + counter = 0;
  57 + };
53 58 window.getNickname = function (name) {
54   - var name = name || $('[name="nick"]').attr('content') || 'Guest' + parseInt(Math.random(0,10)*15);
  59 + var name = name || nick || 'Guest' + parseInt(Math.random(0,10)*15);
55 60 switch (name) {
56 61 case "":
57 62 alert("You did not input a nickname, please reload if you wish to connect.");
@@ -75,9 +80,22 @@ $(document).ready(function(){
75 80 } else {
76 81 row.className = 'btn'
77 82 }
  83 + var style=''
  84 + var row_class =''
  85 + if (nick){
  86 + var reg = nick.replace(/\s+/, "|");
  87 + var regexp = new RegExp(reg,'gi');
  88 + if (regexp.test(message)){
  89 + Tinycon.setBubble(++counter);
  90 + row_class='gold'
  91 + } else {
  92 + row_class='default'
  93 + }
  94 + message = giveMeColors(message);
  95 + }
78 96 row.innerHTML = ''
79 97 + '<th class="author">' + from + '</th>'
80   - + '<td class="msg">' + message.replace(/\[[0-9][0-9]m/g,'') +'<span class="time">'+ (new Date()).toTimeString().substr(0,9)+'</td>';
  98 + + '<td class="msg '+row_class+'">' + message.replace(/\[[0-9][0-9]m/g,'') +'<span class="time">'+ (new Date()).toTimeString().substr(0,9)+'</td>';
81 99 chatBody.append(row);
82 100 scrollBody();
83 101 };
@@ -133,7 +151,6 @@ $(document).ready(function(){
133 151 rv = sock.send(JSON.stringify({ nickname: nickname }));
134 152 }
135 153 } else {
136   - console.log(typeof obj, typeof data)
137 154 if (obj && obj.messagetype) {
138 155 var s = (obj.from == nickname) ? true : false;
139 156 switch (obj.messagetype) {
@@ -194,5 +211,67 @@ $(document).ready(function(){
194 211 return r.toString();
195 212 });
196 213 }
  214 + var ocolors = {
  215 + 'bold' : ['\033[1m', '\033[22m'],
  216 + 'italic' : ['\033[3m', '\033[23m'],
  217 + 'underline' : ['\033[4m', '\033[24m'],
  218 + 'inverse' : ['\033[7m', '\033[27m'],
  219 + 'white' : ['\033[37m', '\033[39m'],
  220 + 'grey' : ['\033[90m', '\033[39m'],
  221 + 'black' : ['\033[30m', '\033[39m'],
  222 + 'blue' : ['\033[34m', '\033[39m'],
  223 + 'cyan' : ['\033[36m', '\033[39m'],
  224 + 'green' : ['\033[32m', '\033[39m'],
  225 + 'magenta' : ['\033[35m', '\033[39m'],
  226 + 'red' : ['\033[31m', '\033[39m'],
  227 + 'yellow' : ['\033[33m', '\033[39m']
  228 + }
  229 + var colors = {
  230 + 'p':['<p>','</p>'],
  231 + '[1m' :['<strong>','</strong>'],
  232 + '[22m' :['<strong>','</strong>'],
  233 + '[3m' :['<i>','</i>'],
  234 + '[23m' :['<i>','</i>'],
  235 + '[4m' :['<u>','</u>'],
  236 + '[24m' :['<u>','</u>'],
  237 + '[7m' :['<span>','</span>'],
  238 + '[27m' :['<span>','</span>'],
  239 + '[37m' :['<span style="color:white">','</span>'],
  240 + '[90m' :['<span style="color:grey">','</span>'],
  241 + '[30m' :['<span style="color:#444">','</span>'],
  242 + '[34m' :['<span style="color:blue">','</span>'],
  243 + '[36m' :['<span style="color:cyan">','</span>'],
  244 + '[32m' :['<span style="color:green">','</span>'],
  245 + '[35m' :['<span style="color:magenta">','</span>'],
  246 + '[31m' :['<span style="color:red">','</span>'],
  247 + '[33m' :['<span style="color:yellow">','</span>']
  248 + }
197 249
  250 + var giveMeColors = function(str){
  251 + var old = str = str ||'[44m'+str+'[43m';
  252 + str = str.split(str.search(/\[[0-9][0-9]m/));
  253 + var text = str.join('').split(/\[[0-9][0-9]m/g);
  254 + var color = str.join('').match(/\[[0-9][0-9]m|\[[0-9]m/g)||'';
  255 + var loop = -1;
  256 + var dohs = 0;
  257 + while (color[loop + 1]){
  258 + var prev = ++loop;
  259 + var next = ++loop;
  260 + if (color[prev]){
  261 + if (colors[color[prev]]){
  262 + var math = (old.search('\\'+color[next])-old.search('\\'+color[prev]))
  263 + if (!(math > 0 && math < 5)){
  264 + old = old.replace(new RegExp('\\'+color[prev]), colors[color[prev]][0])
  265 + old = old.replace(new RegExp('\\'+color[next]),colors[color[prev]][1]);
  266 + } else {
  267 + old = old.replace(new RegExp('\\'+color[prev]), colors[color[prev]][0])
  268 + old = old.replace(new RegExp('\\'+color[next]), colors[color[next]][0])
  269 + old = old.replace(new RegExp('\\'+color[++loop]), colors[color[next]][1])
  270 + old = old.replace(new RegExp('\\'+color[++loop]),colors[color[prev]][1]);
  271 + }
  272 + }
  273 + }
  274 + }
  275 + return old.replace(/\[[0-9]m|\[|[0-9][0-9]m|/g,'');
  276 + }
198 277 });
9 public/js/tinycon.min.js
... ... @@ -0,0 +1,9 @@
  1 +/*
  2 + * Tinycon - A small library for manipulating the Favicon
  3 + * Tom Moor, http://tommoor.com
  4 + * Copyright (c) 2012 Tom Moor
  5 + * MIT Licensed
  6 + * @version 0.2.6
  7 +*/
  8 +
  9 +(function(){var Tinycon={};var currentFavicon=null;var originalFavicon=null;var originalTitle=document.title;var faviconImage=null;var canvas=null;var options={};var defaults={width:7,height:9,font:'10px arial',colour:'#ffffff',background:'#F03D25',fallback:true};var ua=(function(){var agent=navigator.userAgent.toLowerCase();return function(browser){return agent.indexOf(browser)!==-1}}());var browser={chrome:ua('chrome'),webkit:ua('chrome')||ua('safari'),safari:ua('safari')&&!ua('chrome'),mozilla:ua('mozilla')&&!ua('chrome')&&!ua('safari')};var getFaviconTag=function(){var links=document.getElementsByTagName('link');for(var i=0,len=links.length;i<len;i++){if((links[i].getAttribute('rel')||'').match(/\bicon\b/)){return links[i]}}return false};var removeFaviconTag=function(){var links=document.getElementsByTagName('link');var head=document.getElementsByTagName('head')[0];for(var i=0,len=links.length;i<len;i++){var exists=(typeof(links[i])!=='undefined');if(exists&&links[i].getAttribute('rel')==='icon'){head.removeChild(links[i])}}};var getCurrentFavicon=function(){if(!originalFavicon||!currentFavicon){var tag=getFaviconTag();originalFavicon=currentFavicon=tag?tag.getAttribute('href'):'/favicon.ico'}return currentFavicon};var getCanvas=function(){if(!canvas){canvas=document.createElement("canvas");canvas.width=16;canvas.height=16}return canvas};var setFaviconTag=function(url){removeFaviconTag();var link=document.createElement('link');link.type='image/x-icon';link.rel='icon';link.href=url;document.getElementsByTagName('head')[0].appendChild(link)};var log=function(message){if(window.console)window.console.log(message)};var drawFavicon=function(num,colour){if(!getCanvas().getContext||browser.safari||options.fallback==='force'){return updateTitle(num)}var context=getCanvas().getContext("2d");var colour=colour||'#000000';var num=num||0;var src=getCurrentFavicon();faviconImage=new Image();faviconImage.onload=function(){context.clearRect(0,0,16,16);context.drawImage(faviconImage,0,0,faviconImage.width,faviconImage.height,0,0,16,16);if(num>0)drawBubble(context,num,colour);refreshFavicon()};if(!src.match(/^data/)){faviconImage.crossOrigin='anonymous'}faviconImage.src=src};var updateTitle=function(num){if(options.fallback){if(num>0){document.title='('+num+') '+originalTitle}else{document.title=originalTitle}}};var drawBubble=function(context,num,colour){var len=(num+"").length-1;var width=options.width+(6*len);var w=16-width;var h=16-options.height;context.font=(browser.webkit?'bold ':'')+options.font;context.fillStyle=options.background;context.strokeStyle=options.background;context.lineWidth=1;context.fillRect(w,h,width-1,options.height);context.beginPath();context.moveTo(w-0.5,h+1);context.lineTo(w-0.5,15);context.stroke();context.beginPath();context.moveTo(15.5,h+1);context.lineTo(15.5,15);context.stroke();context.beginPath();context.strokeStyle="rgba(0,0,0,0.3)";context.moveTo(w,16);context.lineTo(15,16);context.stroke();context.fillStyle=options.colour;context.textAlign="right";context.textBaseline="top";context.fillText(num,15,browser.mozilla?7:6)};var refreshFavicon=function(){if(!getCanvas().getContext)return;setFaviconTag(getCanvas().toDataURL())};Tinycon.setOptions=function(custom){options={};for(var key in defaults){options[key]=custom.hasOwnProperty(key)?custom[key]:defaults[key]}return this};Tinycon.setImage=function(url){currentFavicon=url;refreshFavicon();return this};Tinycon.setBubble=function(num,colour){if(isNaN(parseFloat(num))||!isFinite(num))return log('Bubble must be a number');drawFavicon(num,colour);return this};Tinycon.reset=function(){Tinycon.setImage(originalFavicon)};Tinycon.setOptions(defaults);window.Tinycon=Tinycon})();

0 comments on commit c409a28

Please sign in to comment.
Something went wrong with that request. Please try again.