MediaWiki:Chat.js

/*	Codes on this page will affect Special:Chat. For stylesheets, use MediaWiki:Chat.css

/* chat &lt;title&gt; modification */ $("head title").html("Wiki Chat - Club Penguin Wiki");

/* allow further interwiki links */

// define Widget Widget = typeof Widget === "undefined" ? {} : Widget;

// define interwiki links feature Widget.interwikiLinks = {};

// function with parameters for custom interwiki links Widget.interwikiLinks.wikiSubDomain = $('link[rel="canonical"]').attr("href").split(".wikia.com/")[0].substr(7); Widget.interwikiLinks.setInterwikiLinks = function(interwiki,url) { if ( $('a[href^="http://' + Widget.interwikiLinks.wikiSubDomain + '.wikia.com/wiki/' + interwiki + ':"]').length > 0 ) { $('a[href^="http://' + Widget.interwikiLinks.wikiSubDomain + '.wikia.com/wiki/' + interwiki + ':"]').each(function {			$(this).attr("href",url + "/wiki/" + $(this).attr("href").split("http://" + Widget.interwikiLinks.wikiSubDomain + ".wikia.com/wiki/" + interwiki + ":")[1]);		}); } }

// apply when message inserted $("body").on("DOMNodeInserted", "section.WikiaPage .Chat li:not(.inline-alert)", function {	Widget.interwikiLinks.setInterwikiLinks("mw","http://www.mediawiki.org");	Widget.interwikiLinks.setInterwikiLinks("mediawikiwiki","http://www.mediawiki.org");	Widget.interwikiLinks.setInterwikiLinks("commons","http://commons.wikimedia.org");	Widget.interwikiLinks.setInterwikiLinks("wikimedia","http://wikimediafoundation.org");	Widget.interwikiLinks.setInterwikiLinks("wikipedia","http://en.wikipedia.org"); });

/* auto refresh emoticons */

setInterval(function {	$.getJSON("/api.php?action=query&format=json&prop=revisions&titles=MediaWiki:Emoticons&rvprop=content&cb=" + new Date.getTime, function(info) { ajaxEmoticons = info.query.pages; for (var pageid in ajaxEmoticons) { ajaxEmoticons = ajaxEmoticons[pageid].revisions[0]["*"].replace(/\\/g,"\\\\").replace(//g,"\x3e").replace(/\"/g,"\\\"").replace(/\'/g,"\\\'"); mw.config.set("EMOTICONS", ajaxEmoticons); }	}); },30000); // loop every 30 seconds

/* resize emoticons */

importStylesheet("MediaWiki:ChatResizeEmoticons.css");

/* !pin command for chat */

importScriptPage("MediaWiki:Chat.js/pin.js");

/* cookie setting */ /* script from the W3School */

// set cookie function setCookie(c_name,value,exdays) { var exdate = new Date; exdate.setDate(exdate.getDate + exdays); var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString); document.cookie = c_name + "=" + c_value; } // get cookie function getCookie(c_name) { var c_value = document.cookie; var c_start = c_value.indexOf(" " + c_name + "="); if (c_start == -1) { c_start = c_value.indexOf(c_name + "="); }	if (c_start == -1) { c_value = null; } else { c_start = c_value.indexOf("=", c_start) + 1; var c_end = c_value.indexOf(";", c_start); if (c_end == -1) { c_end = c_value.length; }		c_value = unescape(c_value.substring(c_start,c_end)); }	return c_value; }

/* chat entrance policy agreement */ /*	alerts a message that asks the user to confirm that he \/ she have read the wiki's policy and agree to follow the rules. reset every 2 months or when the user is kicked \/ banned

// set \/ check Widget Widget = typeof Widget === "undefined" ? {} : Widget;

// create object for the warning widget Widget.policyWarning = {};

// markup Widget.policyWarning.markup = ' \n\ \n\ \t<div style=\"width: 370px; margin: auto; padding: 3px 7px; background: #f6f6f6; background: -moz-linear-gradient(top, #ffffff 0%, #f6f6f6 47%, #ededed 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(47%,#f6f6f6), color-stop(100%,#ededed)); background: -webkit-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); background: -o-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); background: -ms-linear-gradient(top, #ffffff 0%,#f6f6f6 47%,#ededed 100%); background: linear-gradient(to bottom, #ffffff 0%,#f6f6f6 47%,#ededed 100%); border: 1px solid #cccccc; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px;\">\n\ \t\tPlease read carefully before proceeding! \n\ \t\t\n\ \t\t\tBy entering chat, you agree to follow the Club Penguin Wiki\'s policy and its chat policy. \n\ \t\t\t\n\ \t\t \n\ \t \n\ '; // do this when pressing "agree" Widget.policyWarning.agree = function { if (confirm("I've read the policy and promise to follow the wiki's rules") === true) { // agree - close notice and disable message for the next 60 days setCookie("chatPolicy", "agree", 60); $('#policy-notice-blackout, #policy-notice').remove; Widget.policyWarning.clear; } else { // disagree - close window and try again later window.close; } }

// trigger if (typeof getCookie("chatPolicy") !== "string") { $("body").append(Widget.policyWarning.markup); }

// reset if the user is kicked\/banned Widget.policyWarning.clear = function { $("body").on("DOMNodeInserted", "section.WikiaPage .Chat li", function(ev) {		if ( $(ev.target).hasClass("inline-alert") && typeof getCookie("chatPolicy") === "string" && (				$(ev.target).html.indexOf("You have been kicked by ") > -1 ||				$(ev.target).html.indexOf("You have been banned by ") > -1			) ) {			document.cookie = "chatPolicy" + "=; expires=Thu, 01-Jan-70 00:00:01 GMT;";		}	}); } if (typeof getCookie("chatPolicy") === "string") { Widget.policyWarning.clear; }

/*	the following script blocks certain works in certain conditions regex reduction suggested by Callofduty4 http://community.wikia.com/wiki/Thread:628738#7

ChatStringsBlocker = {"count": 0}; $('textarea[name="message"]').on("keypress", function(e) {	if (e.keyCode == 13) {		var a = " " + $('textarea[name="message"]').val.toLowerCase + " ", // the padded spaces are to make sure that matches won't be located in the beginning or ending of the message			b = [				"ass",				"asses",				"bitch",				"bitches",				"bitchy",				"boob",				"boobs",				"cunt",				"dick",				"fuck",				"fucker",				"fucking",				"motherfucker",				"nigga",				"niggas",				"nigger",				"niggers",				"penis",				"penises",				"piss",				"pussy",				"shit",				"shitty",				"tits",				"sex",				"whore",				"whores"			],			escape = "[\\n\\d \\?\\!\\.\\,]+(" + b.join("\n").replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&").replace(/\n/g,"|") + ")[\\n\\d \\?\\!\\.\\,]+"; // decoder from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex#answer-6969486		if (a.split(new RegExp(escape)).length > 1) { // 1 or more matches (no need to globally search) $('textarea[name="message"]').val(""); ChatStringsBlocker.count++; if (ChatStringsBlocker.count < 2) { alert("Warning! You were caught using inappropriate language and your message has been blocked."); } else if (ChatStringsBlocker.count === 2) { alert("LAST WARNING!!!\nIt's the second time you were caught using inappropriate language. A third time would automatically kick you from the chat room!"); } else if (ChatStringsBlocker.count === 3) { window.close; // close on 3rd offense }		}	} });