MediaWiki:FandomizedChat/code.2.1.js

/** * FandomizedChat v2.1 * @description This script makes the chat more modern *             and adds more features that would make *             the chat easier to use. * * @author Ultimate Dark Carnage **/ (function(mw, $, mainRoom, factory, window, undefined) {   if (mw.config.get('wgCanonicalSpecialPageName') == 'Chat') {        if (typeof window.FandomizedChat == 'undefined') {            if (typeof window.FandomizedChatDebug == 'undefined') factory(mw, $, mainRoom, void 0);            else if (window.FandomizedChatDebug === true) factory(mw, $, mainRoom, []);        }    } }(this.mediaWiki, this.jQuery, this.mainRoom, function(mw, $, mainRoom, _debug) { var _main = {}, _isCCChat = (mw.config.get('wgSiteName') == 'Community Central'), debugEnabled = (typeof _debug !== 'undefined' && _debug instanceof Array), arr = [], slice = arr.slice, push = arr.push, o = {}, hasOwn = o.hasOwnProperty, i18n = window.FandomizedChati18n || {}; _main.i18n = $.extend(true, {       en: {            hideChatList: 'Hide Chat List',            showChatList: 'Show Chat List',            away: 'Away',            here: 'Here',            addPing: 'Add Ping',            send: 'Send'        }    }, i18n); _main.importResources = function(resources, callback) { var styles = [], scripts = [], isPlainObject = !(resources instanceof Array), hasCb = typeof callback == 'function', that = this; if (isPlainObject) { $.each(resources, function(_fn, resource) {               var value;                if (typeof _fn !== 'function' && typeof _fn === 'boolean') {                    value = _fn;                    if (value) {                        if (resource.endsWith('.css')) styles[styles.length] = resource;                        else if (resource.endsWith('.js')) scripts[scripts.length] = resource;                    }                } else {                    if (resource.endsWith('.css')) styles[styles.length] = resource;                    else if (resource.endsWith('.js')) scripts[scripts.length] = resource;                    callback.apply(that, [resource]);                }            }); } else { $.each(resources, function(index, resource) {               if (resource.endsWith('.css')) styles[styles.length] = resource;                else if (resource.endsWith('.js')) scripts[scripts.length] = resource;                if (hasCb) {                    callback.apply(that, [resource]);                }            }); }

importArticles({           type: 'style',            articles: styles        }, {            type: 'script',            articles: scripts        }); };

_main.createRailSelfElement = function { var $railHeader = $(' ', {               'class': 'RailHeader rail-header',                'id': 'RailHeader',                html: ' \							 \								 Options \							 \					   '            }), $self = $('#ChatHeader').find('.User').clone(true).addClass('self'); $railHeader.prepend($self); $('#Rail').prepend($railHeader); if (debugEnabled) _debug.push(['RailUserSelf', function(q) {           this.log(q);        }]); };

_main.createSendButton = function { var sendButton = $('', {           'class': 'ChatSendButton wds-button wds-is-stretched',            'href': '#',            text: 'Send',            on: {                'click': function(event) {                    event.preventDefault;                    $('#Write [name="message"]').trigger({ type: 'keypress', which: 13 });               }            }        });

$('#Write').append(sendButton); if (debugEnabled) _debug.push(['CreateSendButton', function(q){           this.log(q);        }]); };   _main.log = function(text){ var logText = 'FandomizedChat asset loaded...$1'; if (typeof text === 'object' && text instanceof Array){ for (var i = 0; i < text.length; i++){ var j = i + 1, t = text[i]; if (t) logText = logText.replace('$' + j, t); }       } else { logText = logText.replace('$1', text); }       console.log(logText); };   _main.debug = function{ var that = this; if (!debugEnabled) return; _debug.forEach(function(object, index){           var name = object[0],                fn = object[1];            if (typeof fn == 'function'){                fn.apply(that, [name]);            }        }); };   _main.createPingList = function{ var $pingList = $(' ', {               'class': 'ChatPingList chat-ping-list',                'id': 'ChatPings'            }), $pingButton = $(' ', {               'class': 'ChatPingListWrapper chat-pings-wrapper',                'id': 'ChatPingsWrapper',                html: [                    $('', { 'class': 'ChatPingButton add-ping', 'id': 'ChatPingButton', html: 'Add Ping +', on: { 'click': function(event){ event.preventDefault; _main.openPingsModal; }                       }                    }),                    $(' ', {})                ]            }),            pingData = JSON.parse(localStorage.getItem('FCPings')) || []; if (pingData.length){ $.each(pingData, function(index, item){               var pingItem = $(' ', { 'class': 'ChatPingItem chat-ping-item', text: item, on: { 'click': function(event){ var text = $(event.target).text; _main.openConfirmModal({                               template: 'Are you sure that you want to remove "$1" from your pings list?',                                values: [text]                            }); }                   }                });                $pingList.append(pingItem);            }); }   };    _main.createi18n = function{ }; }, window));