User:Joeytje50/chat.js

importScript('User:Joeytje50/chatmsg.js') importScript('User:Joeytje50/chat-pings.js')

/* Function to color nicknames of users in the chat, based on their nickname. */ function colorNickNames(el) { if ($('.username:not([style])').length) { var unstyleds = $('.username:not([style])') unstyleds.push(el); $(unstyleds).replaceWith(function { console.log($(this),this);	var string = $(this).html.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).html+'' }) } }

function pad(n) {//Function to pad the timestamps with zeroes where needed return (n<10?'0':'') + n; }

/* Enabling pings */

$('body').append(' '); var pings = 'j[ou]eytje50|j[ou]ey|tje50';

/* Run this when getting a new message */

onchatmessage = function(text, rawtext) { console.log(rawtext) text = badWordsBeep(text); text = unameBeep(text); text = text.replace((new RegExp('|('+pings+'))[^<]+?)('+pings+')','ig')), '$1 $4 ');

return text; //DO NOT EDIT THIS LINE }

/* Simplified version of the chat commands */

$(function {	$('[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 (document.activeElement == document.body && e.which != 32 && e.which != 13) {		$('[name="message"]').focus;	} })

$(window).unbind('mousemove');

$(function {	$('#ChatHeader').prepend(''+ ''+ ' RS Wiki RSC Wiki Wikipedia Google '+ ' '+ ''+ ' input[type="submit"]:active {border-style:inset !important;} ');	$('#rswSearch').submit(function { $('#searchbox').val($('#site').val + $('#searchbox').val) setTimeout(function{$('#searchbox').val('')}, 50) }) })

onNewMessage.push(function(el) {	colorNickNames($(el).find('.username'))

/* 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');	}); })