User:Bovell/Qlicense.js

$(document).ready(function { // Credit to Cakemix for original coding, which used parts of Quarenon/gemwupdate.js        if (document.location.href.indexOf("File:") != -1)        {                var title = wgPageName;

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 cake {                       var b = document.getElementById("aabbcc").value; callAPI(                       {                                'action': 'query',                                'prop': 'info|revisions',                                'intoken': 'edit',                                'titles': title,                                'rvprop': 'content',                                'rvlimit': '1'                        }, 'GET', function (response)                        {                                var pages = response.query.pages;                                var page = null;

for (var i in pages) {                                       page = pages[i]; }

var a = page.revisions[0]['*']; a = a.replace("", "").replace("", "").replace("", ""); //.replace("", "").replace("", "").replace("", "").replace("", "").replace("", "").replace("", ""); a += "\n" + b;                               callAPI(                                {                                        'minor': 'yes',                                        'summary': 'Added license with Quick license.',                                        'action': 'edit',                                        'title': title,                                        '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 h = ""; teabag[""] = "Public domain"; teabag[""] = "Game Screenshot"; teabag[""] = "Fair use"; for (i in teabag) {                       h += "" + teabag[i] + " "; };               var $p = $('#filetoc'); var $form = $(' ');

$form.submit(cake);

var $p2 = $(''); $p2.append("" + h + " "); $p2.append($(' ').css( {                       'margin': '0 1em 0 1em' }).attr( {                       'id': 'aSubmit', 'type': 'submit' }).val('Add license')); $form.append($p2); $p.append($form); } });