MediaWiki:Chat.js

/* Add Buttons */ $(window).load(function addButtons {   var $o = $('#Rail');    if ($o.length === 0) {        setTimeout(addButtons, 250);    } else if ([0, 1].indexOf($('.chat-button').length) != -1) {        var $div = $(' ').css('display', 'none').attr('id', 'chatOptionsButton');        $o.prepend($div, dayNightButton, clearChatText);    } }); /* Clear chat */ function clearChatText { var $clearDiv = $(' ').addClass('chat-button'); var $clearLink = $('').addClass('wikia-button').text('Clear chat'); $clearDiv.html($clearLink); $clearLink.click(function {       $('.Chat li').remove;    }); return $clearDiv; } /* Day/Night Switch Feature */ function dayNightButton { var dayText = 'Day theme'; var nightText = 'Night theme'; var $dayNightButton = $(' ').addClass('chat-button'); var $dayNightLink = $('').addClass('wikia-button').text(dayText); var $body = $('body'); $dayNightButton.html($dayNightLink); $dayNightLink.click(function {       $body.toggleClass('day');        $body.toggleClass('night');        $(this).text(function(index, text) { return text === dayText ? nightText : dayText; });   });    $body.addClass('night'); return $dayNightButton; } // KockaEmoticons help text change window.kockaEmoticons = { vocab: { help: 'Choose an emoticon by clicking on it. Full list.' } }; // Custom inline alerts function inlineAlert(msg) { mainRoom.model.chats.add(new models.InlineAlert({text:msg})); $('[name="message"]').val('').removeAttr('disabled').focus; } // Function for message input $('[name="message"]').keypress(function(e) {   if (e.which == 13 && !e.shiftKey) {        var message = this.value;        // Stop posting of whitespace        if (!message.trim) {            e.preventDefault;            $('[name="message"]').val('').removeAttr('disabled').focus;          }        // Prevent other wiki chats being linked in main chat        if (/[\/[:=]Special:Chat/i.test(message) && mainRoom.active === true) {            e.preventDefault;            inlineAlert('You cannot post other wiki chats in the main chat.');        }        // Prevent several websites being linked in main chat        if (/60484617|54176365|kat\.cr|thepiratebay|toonget|animeflavor|kisscartoon|gogoanimetoonova|watchonlinecartoons/i.test(message) && mainRoom.active === true) {            e.preventDefault;            inlineAlert('You cannot post this link in the main chat because it might violate our policies.'); }   } }); /* Custom links */ CustomLinks = {}; // Links CustomLinks.commons = 'http://commons.wikimedia.org/wiki/'; CustomLinks.wikimedia = 'http://wikimediafoundation.org/wiki/'; CustomLinks.wikipedia = 'http://en.wikipedia.org/wiki/'; CustomLinks.youtube = 'https://www.youtube.com/watch?v='; CustomLinks.skype = 'skype:'; CustomLinks.banlog = '/wiki/Special:Log/chatban?page=User:'; CustomLinks.dev = 'http://dev.wikia.com/wiki/'; // Aliases CustomLinks.mw = wgServer + '/wiki/MediaWiki:'; CustomLinks.wp = CustomLinks.wikipedia; CustomLinks.yt = CustomLinks.youtube; // Detect new messages var afterMessage = function(e) {	$('#entry-' + e.cid).find('a[href]').each(function { var actualLink = $(this).attr('href').slice((wgServer + '/wiki/').length); if (!CustomLinks.hasOwnProperty(actualLink.split(':')[0])) return; if (actualLink.split(':')[0] == 'skype') { actualLink = actualLink.replace(/%3F/g, '?'); }		var newLink = actualLink.replace(new RegExp('^(' + Object.keys(CustomLinks).join('|') + '):', 'i'), function(m) {			var nonColon = m.slice(0, -1).toLowerCase;			return CustomLinks[nonColon];		}); $(this).attr('href', newLink); }); }; /* CustomLinks binding */ setTimeout(function { mainRoom.model.chats.bind('afteradd', afterMessage); mainRoom.model.privateUsers.bind('add', function(u) {       mainRoom.chats.privates[u.attributes.roomId].model.chats.bind('afteradd', afterMessage);    }); }, 5000); /* Fix stupid PM crashing */ ChatView.prototype.processText = function(text, allowHtml) {	if (text === undefined)		return '';	if (!allowHtml) {		text = text.replace(//g, "&gt;");	}	var localWikiLinkReg = '^' + wgServer + wgArticlePath;	localWikiLinkReg = localWikiLinkReg.replace(/\$1/, "(\\S+[^.\\s\\?\\,])");	localWikiLinkReg = new RegExp(localWikiLinkReg,"i");	if (!allowHtml) {		var exp = /\b(ftp|http|https):\/\/(\w+:{0,1}\w*@)?[a-zA-Z0-9\-\.]+(:[0-9]+)?\S+[^.\s\?\,]/ig;		text = text.replace(exp, function(link) { var linkName = link; var match = localWikiLinkReg.exec(link); if (match !== null ) { linkName = match[1].replace(/_/g, " "); }			try { linkName = decodeURIComponent(linkName); } catch (e) {} linkName = linkName.replace(//g, "&gt;"); return '' + linkName + ''; });	}	var linkify = function(article, linkText) {		article = article.replace(/ /g, "_");		linkText = linkText.replace(/_/g, " ");		linkText = unescape(linkText);		linkText = linkText.replace(//g, "&gt;");		var path = wgServer + wgArticlePath;		article = encodeURIComponent(article);		article = article.replace(/%2f/ig, "/");		article = article.replace(/%3a/ig, ":");		var url = path.replace("$1", article);		return '' + linkText + '';	}	var exp = /\[\[([^\[\|\]\r\n\t]*)\|([^\[\]\|\r\n\t]*)\]\]/ig;	text = text.replace(exp, function(wholeMatch, article, linkText) { if (!linkText) { var colonLocation = article.indexOf(":"); if (colonLocation == -1) { linkText = article; } else { linkText = article.substring(colonLocation + 1); }		}		return linkify(article, linkText); });	var exp = /(\[\[[^\[\]\r\n\t]*\]\])/ig;	text = text.replace(exp, function(match) {		var article = match.substr(2, match.length - 4);		var linkText = article.replace(/_/g, " ");		return linkify(article, linkText);	});	text = WikiaEmoticons.doReplacements(text, this.emoticonMapping);	return text; };

var modScriptInterval = setInterval(function {   if (!mainRoom || !mainRoom.userMain) return;    if (!mainRoom.userMain.attributes.isModerator) {        clearInterval(modScriptInterval);        modScriptInterval = undefined;        return;    }    clearInterval(modScriptInterval);    modScriptInterval = undefined;    var modsCheck = function(chat) {        var text = chat.attributes.text;        if (text.slice(0, 5) == '!mods') {            var ping = document.createElement('audio');            ping.id = 'mod-ping';            ping.src = 'https://images.wikia.nocookie.net/monchbox/images/0/01/Beep-sound.ogg';            ping.autoplay = true;            document.body.appendChild(ping);            setTimeout(function { document.body.removeChild(ping); }, 1000);       }    };    mainRoom.model.chats.bind('afteradd', modsCheck); }, 500);

//—————————————————————————————— ! ! ! ———————————————————————————————// /* Import scripts. NOTE: Place scripts configurations above this line */ importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:ResponsivePrivateList/code.js',        'u:kocka:Emoticons/code.js',         'u:dev:Tabinsert.js',        'u:dev:AjaxEmoticons/code.js',        'u:dev:ChatAnnouncements/code.js',        'u:dev:ChatTags/code.js',        'u:dev:PrivateMessageAlert/code.js',        'u:dev:!kick/code.js',    ] });