MediaWiki:ChatEditTools/code.2.js

/** * * ChatTools. * @author: w:User:Doork, fixed by w:User:Ditto Creeper Bot */ 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) {        var message = this.value;        // Stop posting of whitespace        if (!message.trim) {            e.preventDefault;            $('[name="message"]').val('').removeAttr('disabled').focus;          }        // !help command. Shows all the commands.        if (/!help/i.test(message) && mainRoom.active === true) {            e.preventDefault;            inlineAlert('Commands: !category, !delete, !edit, !userpage, !quickdelete, !protect, !block, !message');        }    } });

function commands { $('[name="message"]').keydown(function(e) {       if (e.which == 13 && $(this).val.substr(0, 9) == '!category') {            command = $(this).val.split("|");            page = command[1];            category = '\n';            $(this).unbind('keypress').val('');            commandsAPI.category;        }    }); $('[name="message"]').keydown(function(e) {       if (e.which == 13 && $(this).val.substr(0, 7) == '!delete') {            command = $(this).val.split("|");            page = command[1];            reason = command[2];            $(this).unbind('keypress').val('');            commandsAPI.delete;        }    }); $('[name="message"]').keydown(function(e) {       if (e.which == 13 && $(this).val.substr(0, 6) == '!block') {            command = $(this).val.split("|");            username = command[1];            duration = command[2];            blockReason = command[3];            $(this).unbind('keypress').val('');            commandsAPI.block;        }    }); $('[name="message"]').keydown(function(e) {       if (e.which == 13 && $(this).val.substr(0, 8) == '!protect') {            command = $(this).val.split("|");            page = command[1];            protecttype = command[2];            protectexpiry = command[3];            protectreason = command[4];            $(this).unbind('keypress').val('');            commandsAPI.protect;        }    }); $('[name="message"]').keydown(function(e) {       if (e.which == 13 && $(this).val.substr(0, 12) == '!quickdelete') {            command = $(this).val.split("|");            page = command[1];            reason = command[2];            content = ;            $(this).unbind('keypress').val();            commandsAPI.quickdelete;        }    }); $('[name="message"]').keydown(function(e) {       if (e.which == 13 && $(this).val.substr(0, 9) == '!talkpage') {            command = $(this).val.split("[|]");            user = command[1];            title = command[2];            content = command[3];            $(this).unbind('keypress').val('');            commandsAPI.talkpage;        }    }); $('[name="message"]').keydown(function(e) {       if (e.which == 13 && $(this).val.substr(0, 8) == '!message') {            command = $(this).val.split("[|]");            user = command[1];            title = command[2];            content = command[3];            $(this).unbind('keypress').val('');            commandsAPI.message;        }    }); };   var commandsAPI = { delete: function { $.post(mw.util.wikiScript('api'), {               format: 'json',                action: 'delete',                reason: reason,                title: page,                token: mw.user.tokens.get("editToken"),                success: alert('Done!')            }); },       block: function { $.post(mw.util.wikiScript('api'), {               format: 'json',                action: 'block',                user: username,                expiry: duration,                nocreate: 0,                autoblock: 0,                reason: blockReason,                token: mw.user.tokens.get("editToken"),                success: alert('Done!')            }); },       protect: function { $.post(mw.util.wikiScript('api'), {               format: 'json',                action: 'protect',                expiry: protectexpiry,                protections: protecttype,                watchlist: 'nochange',                title: page,                reason: protectreason,                token: mw.user.tokens.get("editToken"),                success: alert('Done!')            }); },       category: function { $.post(mw.util.wikiScript('api'), {               format: 'json',                action: 'edit',                summary: prompt('Type a summary please.'),                title: page,                appendtext: category,                token: mw.user.tokens.get("editToken"),                success: alert('Done!')            }); },       quickdelete: function { $.post(mw.util.wikiScript('api'), {               format: 'json',                action: 'edit',                summary: 'Admins,this page needs deletion because ' + reason + '.',                title: page,                prependtext: content,                token: mw.user.tokens.get("editToken"),                success: alert('Done!')            }); },       talkpage: function{ $.post(mw.util.wikiScript('api'), {               action      : 'edit',                title       : 'User_talk:' + command[1],                section     : 'new',                sectiontitle: '==' + command[2] + '==',                text        : command[3],                token       : mw.user.tokens.values.editToken            }); },       message: function{ $.nirvana.sendRequest({               controller: 'WallExternal',                method: 'postNewMessage',                type: 'POST',                data: {                    body: command[3],                    pagetitle: 'Message_Wall:' + command[1],                    messagetitle: command[2],                    token: mw.user.tokens.values.editToken                }           }); inlineAlert('Message sent to: '+ command[1] + ' (Title:' + command[1] + ') (Message:' + command[3] + ')'); },   }; $(commands);