User:Joeytje50/chat.js

importScript('User:Joeytje50/chatmsg.js')

/* Function to color nicknames of users in the chat, based on their nickname. */

function colorNickNames { if ($('.username:not([style])').length) { $('.username:not([style])').replaceWith(function {	var string = this.innerHTML.replace(/ ?]*>/i,);	var strlen = string.length	var asciistr = 0;	var addnum = 0;	for (i = 0; i < strlen; i++) {		if (string.charAt(i).match(/[a-z]/i)) {			asciistr += string.charCodeAt(i) - 96;		} else if (string.charAt(i).match(/\d/)) {			asciistr += string.charCodeAt(i) - 47;		} else {			asciistr += string.charCodeAt(i);			addnum += string.charCodeAt(i);		}	}	var color = parseInt(asciistr/(26*string.replace(/[^a-zA-Z0-9]/g,).length+addnum)*16777215).toString(16);	var nickColor = [0,0,0];	nickColor[0] = parseInt(color.charAt(0)+color.charAt(1),16);	nickColor[1] = parseInt(color.charAt(2)+color.charAt(3),16);	nickColor[2] = parseInt(color.charAt(4)+color.charAt(5),16);	nickColor[0] = nickColor[0]>200?nickColor[0]-100:nickColor[0];	nickColor[1] = nickColor[1]>200?nickColor[1]-100:nickColor[1];	nickColor[2] = nickColor[2]>200?nickColor[2]-100:nickColor[2]; nickColor = 'rgb('+nickColor[0]+','+nickColor[1]+','+nickColor[2]+')'; return ''+this.innerHTML+'' }) } }

/* Enabling pings */

$('body').append(' '); var pings = /j(o|u)ey|tje50/ig;

/* Run this when getting a new message */

onchatmessage = function(text, rawtext) { console.log(rawtext) setTimeout(function {		colorNickNames

/* Add chat-mod class in the chat itself to chat mods */ $('.WikiChatList .User.chat-mod .username').each(function {			$('.Chat li[data-user="'+this.innerHTML+'"]').addClass('chat-mod');		});

/* Make it possible to get pinged */ if ($('.Chat ul li:last-child:not(.you)').length && $('.Chat ul li:last-child .message').html.match(pings)) { $('#sound').html(' '); }

}, 20)	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;"')

/* Mark ping phrases */ text = text.replace(pings, ' $& ');

return text; //DO NOT EDIT THIS LINE }

$(function {	onchatmessage(,); });

/* Simplified version of the chat commands */

$('[name="message"]').keypress(function(e) {	if (e.which == 32 || e.which == 13) {		switch (this.value) {			case '/me': this.value = '* '+wgUserName; break;			case '/coppa': this.value = 'http://coppa.org - You must be 13 or older to legally have an account on Wikia.'; break;			case '/cat': this.value = '«(^ω^)»'		}	} })

/* Focus on the message input when a key is pressed, in case you weren't focused on it already. */

$('body').keypress(function(e) {	if (e.which != 32 && e.which != 13) {		$('[name="message"]').focus;	} })