User:King kolton9/chat.js

importScript('User:Joeytje50/chatmsg.js') importScript('User:Joeytje50/chat-pings.js') $('head').append('\n\n\n\n'); 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|dutch'; /* 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 '/santa': this.value = '*<):D';break; case '/zoid': this.value = '(V) (V)';break; }		}		if (e.which == 13) { if (this.value.split(' ')[0] == '/grouphug') { var args = $('[name="message"]').val.replace('/grouphug ','').split(' '); $('[name="message"]').val('* '+wgUserName+' grouphuggles '+args.slice(0,args.length-1).join(', ') + ' and '+args[args.length-1]+'.'); } 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 <option value="google:">Google '+ ' <input id="searchbox" type="search" name="search" placeholder="Search" style="margin:0px;height:20px;">'+ '<input type="submit" name="go" value="Go" style="background-color:buttonface;background-image:none;border:2px outset buttonface;color:buttontext;border-radius:0px;padding:0 5px;">'+ ' 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})		}	} }) /* DISABLED onNewMessage.push(function(el,attrs) {	if ($('#Chat_'+attrs.roomId).is('form#Write+div') && (attrs.user||attrs.name) != wgUserName) {		var msg = $(el).find('.message').html;		var curtext = $('[name="message"]').val;		if (msg == 'caek') {			sendMessage('CAEK :D (caek)');		}		$('[name="message"]').val(curtext)	} });