User:Zootycoon2apple7/chat.js

//Caching $('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) } //End Caching //Creating Alias function createAlias(alias, on, run) { $('[name="message"]').keypress(function(e) {		if (typeof on == 'number') on += ;		if (typeof on == 'string') on = on.split(/[,\|]/);		var val = this.value;		if (on.indexOf(e.which+)!=-1 && val.toLowerCase.search(new RegExp('/'+alias.toLowerCase+'\\b')) == 0) {			val = val.substr(alias.length+(val.charAt(alias.length+1)==' '?2:1));			if (typeof run == 'string') this.value = run + ' ' + val;			else if (typeof run == 'function') run(val, e);			if (e.which!=13) e.preventDefault;		}	}); } //End Create Alias //Kick Command if (wgUserGroups.indexOf('chatmoderator')!=-1 || wgUserGroups.indexOf('sysop')!=-1) { createAlias('kick', 13, function(toKick,e) {		if ($('#WikiChatList [data-user="'+toKick+'"]').length) {			mainRoom.kick({name: toKick})		} else {			if (confirm(toKick + ' is not in this chat. Still try to kick him?')) mainRoom.kick({name: toKick});		}		e.target.value = '';	}); } //End Kick Command //More 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 '/srule': this.value = 'http://creepypasta.wikia.com/wiki/Site_Rules';break; case '/emote': this.value = 'http://creepypasta.wikia.com/wiki/MediaWiki:Emoticons';break; case '/crule': this.value = 'http://creepypasta.wikia.com/wiki/Chat_Rules';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; }	}); }) //Tab Complete function getCaretPos(ctrl) { var CaretPos = 0;   // IE Support if (document.selection) { ctrl.focus ; var Sel = document.selection.createRange ; Sel.moveStart ('character', -ctrl.value.length); CaretPos = Sel.text.length; }   // Firefox support else if (ctrl.selectionStart || ctrl.selectionStart == '0') CaretPos = ctrl.selectionStart; return (CaretPos); } function setCaretPos(ctrl, pos){ if(ctrl.setSelectionRange) {       ctrl.focus; ctrl.setSelectionRange(pos,pos); }   else if (ctrl.createTextRange) { var range = ctrl.createTextRange; range.collapse(true); range.moveEnd('character', pos); range.moveStart('character', pos); range.select; } } //Tab insert for usernames $('[name="message"]').after(' [0,"","",0,null] '); $('[name="message"]').keydown(function(e) {	if (e.keyCode == 9) {		e.preventDefault;		var curval = this.value;		var afData = eval(document.getElementById('autofilldata').innerHTML);		var curpos = afData[3]==0?getCaretPos(this):afData[3];		var carpos = getCaretPos(this)		if ((!curval.charAt(carpos)||curval.charAt(carpos).match(/\s/))&&!curval.charAt(carpos-1).match(/\s/)&&this.value.length) {			var unamestart = ;			if (afData[1].length==0) {				for (i=curpos-1;i>=0&&!curval.charAt(i).match(/\s/);i--) {					unamestart = curval.charAt(i) + unamestart;				}			} else {				unamestart = afData[1];			}			var afterTComplete = ;			for (i=curpos;i<curval.length;i++) {				afterTComplete += curval.charAt(i);			}			//generate list of users			var userList = '';			var userlistelems = document.getElementsByClassName('User');			for (i=0;i=0&&i>=carpos-(!(afData[4]===null)?(matchedNames[afData[4]]?matchedNames[afData[4]].length:0) : unamestart.length)&&matchedNames.length>0;i--) { newval[i] = ''; }			matchedNames = !matchedNames[0]?['']:matchedNames; newval[curpos-unamestart.length] += matchedNames[afData[0]]?matchedNames[afData[0]]:''; newval = newval.join(''); this.value = newval; setCaretPos(this, curpos+(matchedNames[afData[0]].length?matchedNames[afData[0]].length:0)) var iter = afData[0]>=matchedNames.length-1?0:afData[0]+1; document.getElementById('autofilldata').innerHTML = '['+iter+',"'+unamestart+'","'+matchedNames[afData[0]]+'",'+curpos+','+afData[0]+']' }		return false; } else if (e.which != 16) { document.getElementById('autofilldata').innerHTML = '[0,"","",0,null]'; } }).click(function { document.getElementById('autofilldata').innerHTML = '[0,"","",0,null]'; }).blur(function { document.getElementById('autofilldata').innerHTML = '[0,"","",0,null]'; }) //End Tab Complete //Chat Pings var pings = 'Bengy|Benjamin'; importScript('User:Joeytje50/chat-pings.js'); onchatmessage = function(text, rawtext) {	text = unameBeep(text);//remove this line if you don't want username beeps	return text; //DO NOT EDIT THIS LINE } onNewMessage.push(function(el) { var text = $(el).find('.message').html text = text?text:''; var wikilinks = new RegExp('([^<]*)','g')	var rawtext = text.replace(/( |	){2,}/g, ' ').replace(/]*>/g, '$1').replace(wikilinks, function(match,page,title) {return +title+}).replace(/\[\[([^\]]*?) {2,}/g, ']*)\|\1/g, '$1').replace(/[^<]*<\/a>/g, '$1').replace(''+wgServer+'/wiki/', wgServer+'/wiki/') //changing back to original message var onCMCall = onchatmessage(text, rawtext); text = onCMCall?onCMCall:text; $(el).find('.message').html(text) }); if (typeof onchatmessage != 'function') {	var onchatmessage = function(text, format) {		return text; //DO NOT EDIT THIS LINE	} } function inlineAlert(msg) {	document.getElementsByClassName('Chat')[0].getElementsByTagName('ul')[0].innerHTML += ''+msg+'';	document.getElementsByClassName('Chat')[0].scrollTop=document.getElementsByClassName('Chat')[0].scrollHeight	$('[name="message"]').val('').removeAttr('disabled').focus; } function sendMessage(msg) {	mainRoom.sendMessage({which: 13, shiftKey: false, preventDefault: function {}, target: $(' (qc) '+msg+' ') })	$('[name="message"]').removeAttr('disabled').focus; } var pings = pings?pings:wgUserName; var badwords = 'blow ?job|\\barse\\b|\\bass\\b|boner|bitch|clit|cunt|\\bcock\\b|dick|fag|f[üúùûu][çc]k|gay|jerk|nigger|nigga|penis|r.{0,2}tard|wank|whore|badwordstest|##Automated message: Ratelimit passed\\.'; if (!$('#pingsound').length) { $('body').append(' '); } function badWordsBeep(text) { text = text.replace((new RegExp('((^|>|('+badwords+'))[^<]*?)('+badwords+')','ig')), '$1 $4 '); setTimeout(function {		if ($('.Chat ul li:last-child:not(.you):not(.inline-alert) .message .badword').length && $('.Chat ul li:last-child .message').html.match(new RegExp(badwords, 'i'))) {			$('#pingsound').html(' ');		}	}, 20) return text } function unameBeep(text) { text = text.replace((new RegExp('((^|>)[^<]*?)('+pings+')','ig')), '$1 $3 '); setTimeout(function {		if ($('.Chat ul li:last-child:not(.you):not(.inline-alert) .message .highlight').length && $('.Chat ul li:last-child .message').html.match(new RegExp(pings, 'i'))) {			$('#pingsound').html(' ');		}	}, 20) return text } importScriptPage('ChatOptions/code.js', 'dev'); //End Chat Pings