MediaWiki:Illuminati.js

/** * ChatTags - A BBCode parser for Wikia Special:Chat * * Version v2.6.0 * * Copyright (c) 2013 - 2016 Maria Williams. All rights reserved. * * Contributions from: *    Dorumin (SU) */ var chatags = typeof chatags !== 'undefined' ? chatags : {}; chatags.images = typeof chatags.images !== 'undefined' ? chatags.images : false; chatags.videos = typeof chatags.videos !== 'undefined' ? chatags.videos : false; chatags.css = '.chatags-image{max-width:300px;max-height:300px;}'; chatags.tags = { 'b':    function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/b]', ' '); } else { s = s.replace('[b]', ' '); }                return s;             }, 'j':    function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/j]', ' '); } else { s = s.replace('[j]', ' '); }                return s;             }, 'rmzlk':    function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/rmzlk]', ' '); } else { s = s.replace('[rmzlk]', ' '); }                return s;             }, 'bg':   function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/bg]', ' '); } else { try { t = t.split('="');                        t[1] = t[1].replace('"', ''); s = s.replace('[bg="' + t[1] + '"]', ''); } catch(e) { console.log(e) } }                return s;             }, 'big':  function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/big]', ' '); } else { s = s.replace('[big]', ' '); }                return s;             }, 'verybig':  function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/verybig]', ' '); } else { s = s.replace('[verybig]', ' '); }                return s;             }, 'verysmall':  function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/verysmall]', ' '); } else { s = s.replace('[verysmall]', ' '); }                return s;             }, 'extrabig':  function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/extrabig]', ' '); } else { s = s.replace('[extrabig]', ' '); }                return s;             }, 'c':    function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/c]', ' '); } else { try { t = t.split('="');                        t[1] = t[1].replace('"', ''); s = s.replace('[c="' + t[1] + '"]', ''); } catch(e) { console.log(e) } }                return s;             }, 'code': function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/code]', ' '); } else { s = s.replace('[code]', ' '); }                return s;             }, 'font': function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/font]', ' '); } else { try { t = t.split('="');                        t[1] = t[1].replace('"', ''); s = s.replace('[font="' + t[1] + '"]', ''); } catch(e) { console.log(e) } }                return s;             }, 'i':    function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/i]', ' '); } else { s = s.replace('[i]', ' '); }                return s;             }, 'img':  function (s,t) { if (chatags.images !== true) return s;                if (t.charAt(0) !== '/') { try { t = t.split('="');                        t[1] = t[1].replace('"', ''); s = s.replace('[img="' + t[1] + '"]', ''); } catch(e) { console.log(e) } }                return s;             }, 'small': function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/small]', ' '); } else { s = s.replace('[small]', ' '); }               return s;            }, 's':   function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/s]', ' '); } else { s = s.replace('[s]', ' '); }               return s;            }, 'sub': function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/sub]', ' '); } else { s = s.replace('[sub]', ' '); }               return s;            }, 'sup': function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/sup]', ' '); } else { s = s.replace('[sup]', ' '); }               return s;            }, 'u':   function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/u]', ' '); } else { s = s.replace('[u]', ' '); }               return s;            }, 'yt':  function (s,t) { if (chatags.videos !== true) return s;                if (t.charAt(0) !== '/') { try { t = t.split('="');                        t[1] = t[1].replace('"', ''); s = s.replace('[yt="' + t[1] + '"]', ' '); } catch(e) { console.log(e) } }                return s;             } }; chatags.parser = function (s) { var t = s.match(/\[([^\[\];]*)\]/g); var tg = ''; var TAG_LIMIT = 24; if (!t) return s;   t = t.slice(0, TAG_LIMIT); for (var i = 0; i < t.length; i++) { tg = t[i].match(/\[\/?([^\[\]]*)\]/)[1]; try { tg = tg.split('="')[0];       } catch(e) { console.log(e) }        if (typeof chatags.tags[tg] !== 'undefined') {            s = chatags.tags[tg](s, t[i].replace('[', ).replace(']', ));        }    }    return s; }; chatags.init = function {    if (typeof window.mainRoom !== 'undefined') {        $('head').append(' ' + chatags.css + ' ');        window.mainRoom.model.chats.bind("afteradd", function(c) {            if (typeof window.mainRoom.roomId === "undefined")                return;            var string = $("#Chat_" + window.mainRoom.roomId + " .message:last").html;            string = chatags.parser(string);            $("#Chat_" + window.mainRoom.roomId + " .message:last").html(string);        });        window.mainRoom.model.privateUsers.bind('add', function(u) {            var privateRoomId = u.attributes.roomId;            var privateRoom = mainRoom.chats.privates[privateRoomId]; privateRoom.model.chats.bind('afteradd', function(chat) {               if (chat.attributes.isInlineAlert) return;                var string = $("#Chat_" + privateRoomId + " .message:last").html;                    string = chatags.parser(string);                $("#Chat_" + privateRoomId + " .message:last").html(string);            }); });   } }; $(document).ready(function { chatags.init; });