Advertisement
Joeytje50

Untitled

May 8th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //To import this script, add   importScript('User:Joeytje50/irc-chat.js');   to your Special:MyPage/chat.js page.
  2. /*If you don't want nicks to be colored automatically, add
  3.  var irccolornicks = false;
  4. on a line before the import of this script.
  5. */
  6. importScript('User:Joeytje50/chatmsg.js')
  7.  
  8. function colorNickNames() {
  9. if ($('.username:not([style])').length) {
  10. $('.username:not([style])').replaceWith(function() {
  11.     var string = this.innerHTML.replace(/ ?<img[^>]*>/i,'');
  12.     var strlen = string.length
  13.     var asciistr = 0;
  14.     var addnum = 0;
  15.     for (i = 0; i < strlen; i++) {
  16.         if (string.charAt(i).match(/[a-z]/i)) {
  17.             asciistr += string.charCodeAt(i) - 96;
  18.         } else if (string.charAt(i).match(/\d/)) {
  19.             asciistr += string.charCodeAt(i) - 47;
  20.         } else {
  21.             asciistr += string.charCodeAt(i);
  22.             addnum += string.charCodeAt(i);
  23.         }
  24.     }
  25.     var color = parseInt(asciistr/(26*string.replace(/[^a-zA-Z0-9]/g,'').length+addnum)*16777215).toString(16);
  26.     var nickColor = [0,0,0];
  27.     nickColor[0] = parseInt(color.charAt(0)+color.charAt(1),16);
  28.     nickColor[1] = parseInt(color.charAt(2)+color.charAt(3),16);
  29.     nickColor[2] = parseInt(color.charAt(4)+color.charAt(5),16);
  30.     nickColor[0] = nickColor[0]>200?nickColor[0]-100:nickColor[0];
  31.     nickColor[1] = nickColor[1]>200?nickColor[1]-100:nickColor[1];
  32.     nickColor[2] = nickColor[2]>200?nickColor[2]-100:nickColor[2];
  33.     nickColor = 'rgb('+nickColor[0]+','+nickColor[1]+','+nickColor[2]+')';
  34.     return '<a class="username" style="color:'+nickColor+'" href="/wiki/User:'+encodeURIComponent(string)+'" target="_blank">'+this.innerHTML+'</a>'
  35. })
  36. }
  37. }
  38.  
  39. function pad(n) {//Function to pad the timestamps with zeroes where needed
  40.     return (n<10?'0':'') + n;
  41. }
  42.  
  43. onchatmessage = function(text, rawtext) {
  44.     setTimeout(function() {
  45.         colorNickNames()
  46.  
  47.         /* Add chat-mod class in the chat itself to chat mods */
  48.         $('.WikiChatList .User.chat-mod .username').each(function() {
  49.             $('.Chat li[data-user="'+this.innerHTML+'"]').addClass('chat-mod');
  50.         });
  51.  
  52.         /* Add seconds to timestamps */
  53.         var d = new Date();
  54.         var time = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
  55.         var selector = $('form+.Chat ul li:last-child:not(.inline-alert) .time');
  56.         if (selector.length && selector.html().split(':').length != 3) {
  57.             selector.html(time);
  58.         }
  59.     }, 20)
  60.     text = text.replace((new RegExp('<img src=["\']http://i.imgur.com/DexQI.png["\'] width=["\']19["\'] height=["\']19["\']')), '<img src="http://images2.wikia.nocookie.net/runescape/images/d/de/Quick_chat_button.png" style="width:13px;height:10px;"')
  61.  
  62.     return text; //DO NOT EDIT THIS LINE
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement