User:Ultimate Dark Carnage/chat.js

importArticles(/*{   type: 'script',    articles: [        "u:dev:MessageBlocker/code.js",        "u:c:User:Ultimate_Dark_Carnage/commands.js",        "u:c:User:Ultimate_Dark_Carnage/test.js",        "u:c:User:Ultimate_Dark_Carnage/sandbox2.js"    ] }, */{    'type': 'style',    articles: [        'u:c:User:Ultimate_Dark_Carnage/chat2.css'    ] });

function activateCommand(cmd, values){ if (cmd.indexOf('/') === 0){ cmd = cmd.replace(/\/(\w{1,})/gi, '$1'); var user = values.user, font = (cmd = "font") ? values.font : '', txt = values.txt, regexp = values.regexp; if (cmd == "font"){ commands[cmd](font, txt, regexp); } else if (cmd == "ignore" || cmd == "unignore"){ commands[cmd](user); } else if (cmd == "clear"){ commands[cmd]; } else { commands[cmd](txt, user); }   } }

$(function{   if (wgCanonicalSpecialPageName == "Chat"){        if (navigator.userAgent.match(/Windows/gi)) $('.ChatWindow').addClass('Windows');        else if (navigator.userAgent.match(/OS X/gi)) $('.ChatWindow').addClass('OSX');        else if (navigator.userAgent.match(/Linux/gi)) $('.ChatWindow').addClass('Linux');        var commands = {            "terms": function(txt, user){                if (user){                    txt = '' + user + ': Read Wikia\'s Terms of Use';                } else {                    txt = 'Read Wikia\'s Terms of Use';                }            },            "slap": function(txt, user){                txt = '/me slaps ' + user + ' with a big trout.';            },            "clear": function{                if ($('.Chat').find('li').length){                    $('.Chat').find('li').remove;                } },           "ignore": function(user){ if (user){ var el = $('[data-user="' + user + ']');                   if (!el.is('.ignored')){                        el.hide;                        el.addClass('ignored');                    } else {                        return false;                    }                }            },            "unignore": function(user){                if (user){                    var el = $('[data-user="' + user + ']'); if (el.is('.ignored')){ el.show; el.removeClass('ignored'); } else { return false; }               }            },            "font": function(font, txt, regexp){ if (font){ if (font.split(' ').length){ font = font.replace(font, '"' + font + '"'); }                   window.mainRoom.model.chats.bind("afteradd", function(c){                        var s = $('.Chat .message:last').html;                        s = s.replace(regexp, '' + txt + ' ');                        $('.Chat .message:last').html(s);                    }); }           }        };        $('[name="message"]').on('keypress', function(event){            if (event.which == 13 || event.keyCode == 13){                var cmd_regex = /(\/.*) \((.*)\) \(u\:(.*)\)/gi,                    val = $(event.target).val,                    com = val.replace(cmd_regex, '$1'),                    txt = val.replace(cmd_regex, '$2'),                    con = val.replace(cmd_regex, '$3');                activateCommand(com, { user: con, font: con, txt: txt });           }        });    } });

$('#WikiaPage').on('click', function(event){   if (event.ctrlKey && event.shiftKey){        var msg;        if (typeof $(event.target).attr('data-user') === "string" && $(event.target).parents.eq(1).hasClass('Chat')){            msg = $(event.target);        } else if ($(event.target).parents('.Chat > ul > [data-user]').length == 1){            msg = $(event.target).parents('.Chat > ul > [data-user]');        } else msg = false;        if (msg){            var user = mainRoom.model.users.findByName($(msg).attr('data-user'));            if (user){                var menu_html =                    '' +                        '' +                            '' + ' ' + user.attributes.name + ' ' + ' ' +                       '' + '' + 'Ignore' + '' + '' + 'Slap' + '' + '' + 'Kick' + '</li>' + '' + '<a href="javascript:void(0);">Ban</a>' + '</li>' + '' + '<a href="javascript:void(0);">Block</a>' + '</li>' + '' + '<a href="javascript:void(0);">Check Edits</a>' + '</li>' + '</ul>' + ' ';               $('.ChatWindow').append($(menu_html).css({ "top": event.pageY + 'px', "left": event.pageX + 'px', "position": "absolute"})); $('#options-menu .menu-item').on('click', function(ev){                   if ($(ev.target).is('[data-type="ignore"]')){                        var el = $('.ChatWindow [data-user="' + user.attributes.name + '"]');                        el.hide;                    } else if ($(ev.target).is('[data-type="slap"]')){                        var txt = '/me slaps ' + user.attributes.name + ' with a very large trout';                        if ($('#Write [name="message"]').length){                            $('#Write [name="message"]').val(txt);                        }                    } else if ($(ev.target).is('[data-type="kick"]')){                        if (wgUserGroups.indexOf('vstf') + wgUserGroups.indexOf('staff') + wgUserGroups.indexOf('helper') + wgUserGroups.indexOf('sysop') + wgUserGroups.indexOf('chatmoderator') > -5){                            mainRoom.kick({ name: user.attributes.name });                       } else {                            return false;                        }                    } else if ($(ev.target).is('[data-type="ban"]')){                        if (wgUserGroups.indexOf('vstf') + wgUserGroups.indexOf('staff') + wgUserGroups.indexOf('helper') + wgUserGroups.indexOf('sysop') + wgUserGroups.indexOf('chatmoderator') > -5){                            var form_html =                                 '<form class="WikiaForm ban-form" id="ban-form" method="" name="ban-form">' +                                    '<header class="ban-form-header" id="ban-form-header">' +                                        ' Ban ' + user.attributes.name + ' ' +                                    ' ' +                                    '<section class="ban-form-section" data-section-name="length">' +                                        '<label for="ban-form-expiry" class="ban-form-label">Expiry ' + '<input type="text" id="ban-form-expiry" name="expiry" />' + ' ' +                                   '<section class="ban-form-section" data-section-name="reason">' + '<label for="ban-form-reason" class="ban-form-label">Reason ' + '<textarea id="ban-form-reason" name="reason" rows="3" cols="8"> ' + ' ' +                               ' ';                            $('.ChatWindow').append($(form_html).css({ "top": event.pageY + 'px', "left": event.pageX + 'px', "position": "absolute"})); $('.ban-form#ban-form').on('submit', function(e){                               if (e.target){                                    e.preventDefault;                                    var expiry = $('#ban-form-expiry').val,                                        reason = $('#ban-form-reason').val;                                    var b = new BanCommand({ userToBan: user.attributes.name, time: expiry, reason: reason });                                   mainRoom.socket.send(b.xport);                                    $(e.target).remove;                                }                            }); }                   }                    $(ev.target).parents('#options-menu').remove; });           }        }    } });