User:BLUEBIRD/global.js

// @todo move inline styling to classes and define in MediaWiki:Wikia.css (which is imported to chat)

//Chat's topic. Remember to escape single quotes in the topic using \' to prevent this from breaking. var chatTopic = 'Welcome to the RuneScape Wiki chat. Rules • Information • Logs • Quick Chat' $(function {	$('#ChatHeader .public.wordmark').prepend(''+chatTopic+' ')	.find('a').attr('style','position:relative;text-decoration:underline;') }) $('#ChatHeader .public.wordmark div:not(:first-child)').remove

window.aliases = {};

/** * Creates the alias for usage in the chat * * @param cmd {string}			Name of the alias.

* @param on {string; number; array}	The keycodes for the keys that should trigger the alias activating. Defaults to 13 (enter). See http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes for more codes. Allowed syntax: String with comma-seperated values; number of the keycode; or array with all keycodes.

* @param run {function; string}	Function to run when the command is used. Allowed syntax: function; string the new value of the input field should be. Function syntax: First argument contains the input's value, second argument contains event  object.

* @param midLine {boolean} (optional)	Set to true if the command is meant for mid-sentence too, and will trigger the run function even when the command is not at the start of a line. Command will not automatically get a slash prefix. */

function createAlias(cmd, on, run, midLine) { window.aliases[cmd] = function(e) { if (!on) on = '13'; if (typeof on == 'number') on += ''; if (typeof on == 'string') on = on.split(/[,\|]/); var val = this.value; if (midLine) var hasAlias = val.search(new RegExp('\\b'+cmd+'\\b','i')) != -1; else var hasAlias = val.search(new RegExp('/'+cmd+'\\b', 'i')) == 0; if (on.indexOf(e.which+'')!=-1 && hasAlias) { if (!midLine) val = val.substr(cmd.length+(val.charAt(cmd.length+1)==' '?2:1)); if (typeof run == 'string') { if (midLine) this.value = val.replace(new RegExp('\\b'+cmd+'\\b','ig'), run); else this.value = run + ' ' + val; } else if (typeof run == 'function') run(val, e); if (e.which!=13) e.preventDefault; }	}	$('[name="message"]').keypress(window.aliases[cmd]); }

/* Tab Insert */ importScript('User:Joeytje50/tabinsert.js');

/* Rate Limit */ importScript('User:Joeytje50/ratelimit.js');

/*Adding Quick Chat thing per discussion in Chat*/ importScript('User:Joeytje50/qc.js');

/*Script that makes it easy to run functions when receiving messages*/ importScript('MediaWiki:Chat.js/newmessage.js');

/*Mark admins*/ setInterval(function {	$('#Rail .User.chat-mod:not(.admin) .username').each(function { if (!this.innerHTML.match(/N7 Elite|Atheist723|Casting Fishes\^\^|Hofmic|Flaysian|Touhou FTW/)) { $(this).parent.addClass('admin'); }	}); }, 1000)

/*Allow Chat Mods and admins to kick users using /kick */ 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 = '';	}); }

/*Script that changes Google Image Search urls to the short url, and notifies the user that they should click for the full image url next time instead.*/ createAlias('imgres','13,32', function(val,e) {	var dis = e.target;	var re = /(https?:\/\/)?(www\.)?google\.(co\.)?\w{2,3}\/imgres\?([^&]*&)*imgurl=([^&\s]+)[^ ]*/i;	if (!val.match(re)) return false;	document.getElementsByClassName('Chat')[0].getElementsByTagName('ul')[0].innerHTML += ''+' It looks like you tried to share a link via Google Images. Please click "View image" on the Google Images page to view the full image before sharing it, in order to keep the link shorter. '+'';	document.getElementsByClassName('Chat')[0].scrollTop=document.getElementsByClassName('Chat')[0].scrollHeight	dis.value = dis.value.replace(re,'$5'); }, true);

/* Making list of users fit more easily */ padding: 4px 4px 4px 46px; }
 * 1) WikiChatList > li {

/* Thing for chatmod stars */ .User.chat-mod .username:after, .User.staff .username:after {background-image:none !important;}

.user .username:after {right: 6px !important;}

/* Custom Chatmod Star */ .User.chat-mod .username:after { content: url("http://images.wikia.com/runescape/images/6/69/Admin_clan_rank.png"); } .User.chat-mod.admin .username:after { content:url("http://images.wikia.com/runescape/images/8/88/Organiser_clan_rank.png"); } .User.chat-mod.admin.staff .username:after { content:url("http://images.wikia.com/runescape/images/8/89/Overseer_clan_rank.png"); }

.Write img { left: 11px; position: absolute; height: 33px; width: 33px; }

i, em {font-style:italic !important;}

.Chat .inline-alert * {display: inline;}

img[onload] { width: 0px !important; height: 0px !important; border: none !important; }

.Chat li .boundary {display:none;}

.Chat .message {word-wrap:break-word;}

/* Changes the colour of text you type before being sent back to black */ .Write [name="message"] {color: black !important;} .WikiaPage {border: 1px solid #CCC6B0 !important;}

/* Prevent overlapping of chat alert */ .Chat .quick-chat { margin-bottom:10px; }

function importScript(b){var a=mw.config.get('wgScript')+"?title="+encodeURIComponent(b.replace(/ /g,"_")).replace(/%2F/ig,"/").replace(/%3A/ig,":")+"&action=raw&ctype=text/javascript";return importScriptURI(a)} function importScriptURI(a){var b=document.createElement("script");b.setAttribute("src",a);b.setAttribute("type","text/javascript");document.getElementsByTagName("head")[0].appendChild(b);return b} function importScriptPage(b,d){var a="/index.php?title="+encodeURIComponent(b.replace(/ /g,"_")).replace("%2F","/").replace("%3A",":")+"&action=raw&ctype=text/javascript";if(typeof d=="string"){if(d.indexOf("://")==-1){a="http://"+d+".wikia.com"+a}else{a=d+a}}return importScriptURI(a)} function importStylesheet(a){return importStylesheetURI(mw.config.get('wgScript')+"?action=raw&ctype=text/css&title="+encodeURIComponent(a.replace(/ /g,"_")))} function importStylesheetURI(b,d){var a=document.createElement("link");a.type="text/css";a.rel="stylesheet";a.href=b;if(d){a.media=d}document.getElementsByTagName("head")[0].appendChild(a);return a} function importStylesheetPage(b,d){var a="/index.php?title="+encodeURIComponent(b.replace(/ /g,"_")).replace("%2F","/").replace("%3A",":")+"&action=raw&ctype=text/css";if(typeof d=="string"){if(d.indexOf("://")==-1){a="http://"+d+".wikia.com"+a}else{a=d+a}}return importStylesheetURI(a)} function addOnloadHook(func) {$(func);} importScript('User:'+mw.config.get('wgUserName')+'/chat.js'); importStylesheet('User:'+mw.config.get('wgUserName')+'/chat.css'); var onNewMessage = [], onStatusMessage = [];

/* SYNTAX: For running a script when you get a new message: onchatmessage = function(text, rawtext) { //Scripts to run when you get a new message return text; //DO NOT EDIT THIS LINE } For sending a new message or an inline alert, respectively: sendMessage('Message'); inlineAlert('Message'); 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+'</li>'; 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; }

function aListener(chat) { //do stuff } mainRoom.model.chats.bind('afteradd', aListener);