MediaWiki:Chat.js

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;             }, '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;             }, '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;             }, 'glow':    function (s,t) { if (t.charAt(0) === '/') { s = s.replace('[/glow]', ' '); } else { try { t = t.split('="');                        t[1] = t[1].replace('"', ''); s = s.replace('[glow="' + t[1] + ' ' + t[2] + '"]',''); } 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 = ''; if (!t) return s;   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) {            var string = $("#Chat_" + roomId + " .message:last").html;            string = chatags.parser(string);            $("#Chat_" + roomId + " .message:last").html(string);        });    } };

$(document).ready(function {   chatags.init;    $('.Chat ul').append('This is a custom ChatTags thing made by a smug frick!'); });