User:PassionFruitMaster/chat.js

var changeLogInterval = function{ $(' ', {       text: 'Change Log Interval',        style: 'bottom:55px',        onclick: 'logInterval = parseInt(prompt("Change " + logInterval + " milliseconds to what?", 120000))'    }).appendTo(".Rail"); } importScriptPage('User:Joeytje50/ChatLogger.js', 'runescape'); changeLogInterval; // Console Log console.log('Loaded: User:PassionFruitMaster/chat.js');

importScript('User:Joeytje50/chatmsg.js', 'runescape'); importScript('User:Joeytje50/chat-pings.js', 'runescape'); /*if (navigator.platform.match("Linux")) $('body').addClass('Linux') else if (navigator.platform.match("Win")) */$('body').addClass('Windows') //TODO: Make something that deletes old messages in mobile chat, so that it lags less. $('head').append('\n\n\n\n'); function setIntervalX(func, delay, amt) { var ran = 0; var itv = setInterval(function {		if (ran++ < amt) {			func;		} else {			clearInterval(itv);		}	}, 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]+')'; var original = $($(this).html+' '); if (original.length==4) { original = [original.get(0).outerHTML, string, original.get(2).outerHTML]; } else { original = [,$(this).html,]; }	return ''+original[0]+''+original[1]+''+original[2]+' ' }); } } function pad(n) {//Function to pad the timestamps with zeroes where needed	return (n<10?'0':) + n; } /* Enabling pings */ $('body').append(' '); var pings = window.pings||'j[ou]eytje50|j+[ou]+e+y+|tje50|dutch'; /* Run this when getting a new message */ onchatmessage = function(text, rawtext) {	//text = badWordsBeep(text);	text = unameBeep(text);	if ($('body').is('.Windows')) 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 = ; createAlias('coppa', '13,32', 'http://coppa.org - You must be 13 or older to legally have an account on Wikia.'); createAlias('cat', '13,32', '«(^ω^)»'); createAlias('santa', '13,32', '*<):D'); createAlias('zoid', '13,32', '(V) (V)'); $(function { $('[name="message"]').keypress(function(e) {		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 <option value="wikipedia:">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) } }); $('[name="message"]').keypress(function(e) { if (e.which == 13) { this.value = this.value.replace(/(\s|^)(([a-z0-9][a-z0-9-]+[a-z0-9]\.)+\w{2,4}\/[^\s]+|www\.([a-z0-9][a-z0-9-]+[a-z0-9]\.)\w{2,4})/gi, '$1http://$2'); } }); if (navigator.platform.match("Linux")) {//For mobile	$('[name="message"]').keydown(function(e) { NodeChatDiscussion.prototype.scrollToBottom.apply({chatDiv:$('#Chat_'+roomId)}); }); }