User:Lost Labyrinth/QReportAdder.js

$(function {    if (!$('#QuickReportAdder')) {        return;    }    function callAPI(data, method, callback) {        data['format'] = 'json';        $.ajax({ data: data, dataType: 'json', url: wgScriptPath + '/api.php', type: method, success: function (response) { if (response.error) { alert('API error: ' + response.error.info); } else { callback(response); }           },            error: function (xhr, error) { showError('AJAX error: ' + error); },           timeout: 10000 // msec });   }    function ReportInsert {        if (!$('#Userinput').val) {            alert("Fill in the input please.");            return false;        }        $('#ReportInsertSubmit').val('Reporting user');        callAPI({ 'action': 'query', 'prop': 'info|revisions', 'intoken': 'edit', 'titles': 'The Sims Wiki:Report', 'rvprop': 'content', 'rvlimit': '1' }, 'GET', function (response) { var pages = response.query.pages; var page = null; for (var i in pages) { page = pages[i]; }           var dataInput = '*'; var a = page.revisions[0]['*']; if (a.indexOf('') > 1) { a = a.replace('*', dataInput); } else { a = a.replace("\r*{{Report|", dataInput + "\r" + "*{{Report|"); }           callAPI({                'minor': 'yes',                'summary': 'Added report with Quick Report adder.',                'action': 'edit',                'title': 'The Sims Wiki:Report',                'basetimestamp': page.revisions[0].timestamp,                'startimestamp': page.starttimestamp,                'token': page.edittoken,                'text': a            }, 'POST', function (response) {                if (response.edit.result == 'Success') {                   document.location.replace(wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=purge');                } else {                    alert('An error occurred while submitting the edit.');                }            }); });       return false;    }    var $form = $(' ');    $form.submit(ReportInsert);    var $input = $('');    $input.append($(' ').css({        'for': 'Userinput',        'width': '4em',        'float': 'left',        'text - align': 'right',        'margin - right': '0.5em',        'display': 'block'    }).text('User:'));    $input.append($(' ').attr({        'id': 'Userinput',        'type': 'text',        'size': 10    }));    $input.append($(''));    $input.append($(' ').css({        'for': 'Userinput',        'width': '4em',        'float': 'left',        'text - align': 'right',        'margin - right': '0.5em',        'display': 'block'    }).text('Reason:'));    $input.append($(' ').attr({        'id': 'Reasoninput',        'type': 'text',        'size': 10    }));    $input.append($(''));    $input.append($(' ').attr({        'id': 'ReportInsertSubmit',        'type': 'submit' }).val('Report user')); $form.append($input); $('#QuickReportAdder').html($form); });