User:Joeytje50/chat.js

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

function setIntervalX(func, delay, amt) { var ran = 0 var int = setInterval(function {		if (ran++ < amt) {			func		} else {			clearInterval(int)		}	}, delay) }

/* Function to color nicknames of users in the chat, based on their nickname. */ function colorNickNames(el) { var selector = '.username:not([style])' if ($(selector).length) { var unstyleds = $(selector); el&&el.html?unstyleds.push(el):undefined; $(unstyleds).replaceWith(function {	var string = $(this).html.replace(/ ?]*>/i,).replace(/ .{1,4}<\/span>/g, );	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 */

var lastMessage = ''; $(function {	$('[name="message"]').keypress(function(e) { if (e.which == 32 || e.which == 13) { switch (this.value) { 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 = '«(^ω^)»';break; case '/zoid': this.value = '(V) (V)';break; }		}		if (e.which == 13) { if (this.value.split(' ')[0] == '/kick') { e.preventDefault; var toKick = this.value.replace(/^\/kick /,'') if (!$('#WikiChatList [data-user="'+toKick+'"]').length) { confirm(toKick + ' is not in this chat. Still try to kick him?')?mainRoom.kick({name: toKick}):undefined; } else { mainRoom.kick({name: toKick}) }				this.value = ''; return true; } else { switch (this.value) { case '/clear': this.value = ''; $('.Chat[style*="block"] ul, .Chat[style=""] ul').html('Window cleared');break; }				lastMessage = this.value; }		}	}).keydown(function(e) { if (e.which == 38 && this.value == '') { this.value = lastMessage; $(this).select; }	}); })

/* 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) {	if ($(el).find('.username')) {		colorNickNames($(el).find('.username'));	}	setTimeout(colorNickNames,20);	setIntervalX(colorNickNames,250,3);	setTimeout(colorNickNames,1500);

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

$('body').dblclick(function(e) {	if ($(e.target).is('.Chat .avatar, .Chat .message .badword')) {		var toKick = $(e.target).parents('li').attr('data-user');		if (confirm('Kick '+toKick+'?')) {			mainRoom.kick({name: toKick})		}	} })

function sendStatusMessage(msg,user) { var setStatusCommand = new models.SetStatusCommand({		statusState: STATUS_STATE_PRESENT,		statusMessage: user.replace(' ','_') + ' ' + msg	}); mainRoom.socket.send(setStatusCommand.xport); }

models.User = Backbone.Model.extend({	defaults: {		'name': ,		'since': ,		'statusMessage': '',		'statusState': STATUS_STATE_PRESENT,		'isModerator': false,		'isStaff': false,		'isCanGiveChatMode': false,		'avatarSrc': "http://placekitten.com/50/50",		'editCount': '?',		'isPrivate': false,		'active': false,		'privateRoomId': false	},	initialize: function(options){		attrs = this.attributes;		console.log(JSON.stringify(attrs), attrs, attrs == eval(JSON.stringify(attrs)));		if (attrs.statusMessage.length && attrs.statusMessage.split(' ')[0] == wgUserName.replace(' ','_') && attrs.name != wgUserName) {			console.log('running statusMessage functions:')			for (var i in onStatusMessage) {				onStatusMessage[i](options)			}		}	},	isAway: function{		return (this.get('statusState') == STATUS_STATE_AWAY);	} });

/*	var message = data.statusMessage; var user = data.name; var usergroup = isStaff?'staff': isCanGiveChatMode?'sysop': isModerator?'mod':'user';

onStatusMessage.push(function(data) {	var message = data.statusMessage;	var user = data.name;	var msgparams = message.split(' ');	var userName = wgUserName.replace(' ','_');	if (msgparams[1] == 'NAMEREQ') {		sendStatusMessage('NAMEREPLY ' + getCookie('ign'), data.name)	} else if (msgparams[1] == 'NAMEREPLY') {		inlineAlert(user + "'s ingame name is " + msgparams[2]);	} })