MediaWiki:Chat.js

importScriptPage('MediaWiki:ChatTags/code.js', 'shining-armor');

// Chat options importScriptPage('ChatOptions/code.js', 'dev');

$(function {	/* self badge */	var g = mw.config.get("wgUserGroups"),		order = ["bureaucrat", "sysop", "junioradmin", "threadmoderator", "chatmoderator", "bot"],		myGroups = mw.config.get("wgUserGroups"),		dominantGroup;		icons = {                       "bureaucrat": "http://images1.wikia.nocookie.net/hypotheticalhurricanes/images/thumb/0/09/Bureaucrat_Star_HH.png/16px-Bureaucrat_Star_HH.png",			"sysop": "http://images4.wikia.nocookie.net/hypotheticalhurricanes/images/thumb/a/a0/Sysop_Star_HH.png/16px-Sysop_Star_HH.png",                        "junioradmin": "http://images4.wikia.nocookie.net/hypotheticalhurricanes/images/thumb/0/09/Junioradmin_Star_HH.png/16px-Junioradmin_Star_HH.png",                        "threadmoderator": "http://images4.wikia.nocookie.net/hypotheticalhurricanes/images/thumb/1/10/Threadmoderator_Star_HH.png/16px-Threadmoderator_Star_HH.png",                        "chatmoderator": "http://images2.wikia.nocookie.net/hypotheticalhurricanes/images/thumb/1/18/Chat_Mod_Star_HH.png/16px-Chat_Mod_Star_HH.png", "bot": "http://images2.wikia.nocookie.net/hypotheticalhurricanes/images/thumb/e/e0/Bot_Star_HH.png/16px-Bot_Star_HH.png" };	for (var i in order) { var currGroup = order[i]; if (myGroups.indexOf(currGroup) > -1) { dominantGroup = currGroup; break; }	}	if (typeof dominantGroup === "string") { $("body").addClass("cugroup-" + dominantGroup); mw.util.addCSS(			'body.cugroup-' + dominantGroup + ' #ChatHeader > .User > .username:after {\n' +				'\tbackground-image: url(\'' + icons[dominantGroup] + '\');\n' +				'\tbackground-position: 0 0;\n' +			'}'		); }

/* badges user list */ $.when(	       $.getJSON("/api.php?action=query&format=json&list=allusers&augroup=bureaucrat&aulimit=max&cb=" + new Date.getTime),                $.getJSON("/api.php?action=query&format=json&list=allusers&augroup=sysop&aulimit=max&cb=" + new Date.getTime),                $.getJSON("/api.php?action=query&format=json&list=allusers&augroup=junioradmin&aulimit=max&cb=" + new Date.getTime),                $.getJSON("/api.php?action=query&format=json&list=allusers&augroup=threadmoderator&aulimit=max&cb=" + new Date.getTime),                $.getJSON("/api.php?action=query&format=json&list=allusers&augroup=chatmoderator&aulimit=max&cb=" + new Date.getTime),                $.getJSON("/api.php?action=query&format=json&list=allusers&augroup=bot&aulimit=max&cb=" + new Date.getTime)	).done(function(data_bureaucrat, data_sysop, data_junioradmin, data_threadmoderator, data_chatmoderator, data_bot) { var users = { "bureaucrat": data_bureaucrat[0].query.allusers, "sysop": data_sysop[0].query.allusers, "junioradmin": data_junioradmin[0].query.allusers, "threadmoderator": data_threadmoderator[0].query.allusers, "chatmoderator": data_chatmoderator[0].query.allusers, "bot": data_bot[0].query.allusers, },			checkedUsers = [], cssData = {}, cssOutput = ""; for (var i in order) { var currGroup = order[i]; for (var j in users[currGroup]) { var currUser = users[currGroup][j]; if (checkedUsers.indexOf(currUser.name) == -1 && currUser.id > 0) { checkedUsers.push(currUser.name); if (!cssData.hasOwnProperty(currGroup)) { cssData[currGroup] = []; }					cssData[currGroup].push('body.ChatWindow #Rail .User[data-user="' + currUser.name + '"] .username:after'); }			}		}		for (var i in order) { if (typeof cssData[order[i]] === "object") { cssOutput += (					cssData[order[i]].join(",") + '{' +						'background-image: url(\'' + icons[order[i]] + '\');' +					'background-position: 0 0;' +					'}'				); }		}		mw.util.addCSS(cssOutput); }); }); // All credit goes to Penguin-Pal // $(function {	var gap = 30,		chatResizeEmoticons = $('');	$(chatResizeEmoticons).appendTo("head");	function request {		$.getJSON("/api.php?action=query&format=json&prop=revisions&titles=MediaWiki:Emoticons|MediaWiki:ChatResizeEmoticons.css&rvprop=content&cb=" + new Date.getTime, function(data) { var a = data.query.pages, content = {emoticons: [], css: ""}; for (var pageid in a) { if (a[pageid].title == "MediaWiki:ChatResizeEmoticons.css") { $(chatResizeEmoticons).html(a[pageid].revisions[0]["*"]); } else { content.emoticons.push(a[pageid].revisions[0]["*"]); }			}			mw.config.set("EMOTICONS", content.emoticons.join("\n\n")); });	}	// make first request when joining the room	request;	// request again every every 'gap' seconds	setInterval(request, gap * 1000); });