User:Doork/wikia.js

/** * * ChatEditTools. * @author: w:User:BlackZetsu */ function start { mainRoom.model.chats.add(new models.InlineAlert({ text: ('ChatEditTools is enabled') })); }

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, 5) == '!edit') {            command = $(this).val.split("/");            page = command[1];            content = command[2];            $(this).unbind('keypress').val('');            commandsAPI.edit;        }    });

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!')            }); },       category: function { $.post(mw.util.wikiScript('api'), {               format: 'json',                action: 'edit',                summary: 'Adding: ' + command[2],                title: page,                appendtext: category,                token: mw.user.tokens.get("editToken"),                success: alert('Done!')            }); },       edit: function { $.post(mw.util.wikiScript('api'), {               format: 'json',                action: 'edit',                summary: 'Adding some content',                title: page,                appendtext: content,                token: mw.user.tokens.get("editToken"),                success: alert('Done!')            }); },   }; } $(start); $(commands);

///Use !message\Username\Title\Body $('[name="message"]').keypress(function (e) {   if (e.which == 13) {        var test = "!message";        if (this.value.indexOf(test) > -1 && this.value.indexOf(test) < 8) {            var query = this.value.replace('!message');            command = $(this).val.split("\\");           $.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 },               callback: function { alert('Message sent!'); },               onErrorCallback: function(e) { alert('An error occurred.'); }           });                    }                    $(this).unbind('keypress').val('');    } });

///Use !userpage\Username\Title\Body $('[name="message"]').keypress(function (e) {   if (e.which == 13 && $(this).val.substr(0, 9) == '!userpage') {        var test = "!userpage";        if (this.value.indexOf(test) > -1 && this.value.indexOf(test) < 8) {            var query = this.value.replace('!userpage');            command = $(this).val.split("User=");                                       $.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 });           };                    $(this).unbind('keypress').val('');        } });