User:Cakemix/Qlicense.js

$(document).ready(function { 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) {       showError('API error: ' + response.error.info); }   else {       callback(response); } }, error: function(xhr, error) {   showError('AJAX error: ' + error); }, timeout: 10000 // msec } ); } function edit(b) {   callAPI( {       'action': 'query', 'prop': 'info|revisions', 'intoken': 'edit', 'titles': wgPageName, '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("", ""); a += b;   callAPI(    {        'minor': 'yes',        'summary': 'Added license with User:Ikin/Installs Quick License.',        'action': 'edit',        'title': wgPageName,        'basetimestamp': page.revisions[0].timestamp,        'startimestamp': page.starttimestamp,        'token': page.edittoken,        'text': a    }, 'POST', function(response) {    if (response.edit.result == 'Success')    {        alert("Updated the page.");        document.location.replace(wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=purge');    }    else    {        alert('An error occurred while submitting the edit.');    } }); }); return false; } if (document.location.href.indexOf("wiki/File:") != -1) { $('#filetoc').append( "Public domain (PMG) "+ "Game screenshot "+ "Fair use" ); } else if(document.location.href.indexOf("&action=edit") != -1) { $('#toolbar').prepend("" + "Licenses "+ "Public domain (PMG) "+ "Game Screenshot "+ "<option value='\n'>Fair use "+ " "); } });