User:ITechieGamer/test.js

$(document).ready(function { var $testGroup = $(' ').append($('Test scripts ')),      $testBody = $(' '),      $testLink = $('Merge with Block icons');  $($testGroup.append($testBody.html($('').append($('').html($testLink))))).insertBefore('#p-socialProfiles');  $('#t-test1').click(testFunction); });

function testFunction {

var editToken, output = [], pages = [], success = 0;

console.log('Getting members of category "Block renders"');

$.ajax({ type: 'GET',  url: mw.util.wikiScript('api'),  data: {    format: 'json',    formatversion: 2,    action: 'query',    list: 'categorymembers',    cmtitle: 'Category:Block_renders',    cmlimit: 500  },  dataType: 'json',  async: false,  success: function(response) {    var cm = response.query.categorymembers;    for(var a in cm) {      pages.push(cm[a].title);      $.ajax({ type: 'GET', url: mw.util.wikiScript('index'), data: { title: cm[a].title, action: 'raw' },       async: false, success: function(response) { output.push(response); },       error: function(xhr, textStatus, error) { console.log(xhr.statusText + '\n' + textStatus + '\n' + error); alert('Error while getting raw contents of "' + cm[a].title + '"'); return; }     });    }  },  error: function(xhr, textStatus, error) {    console.log(xhr.statusText + '\n' + textStatus + '\n' + error);    alert('Error while getting members of category "Block renders"');    return;  } });

console.log('Working on the raw contents of pages');

for(var a in output) { output[a] = output[a].replace('\n', ).replace(, ''); }

console.log('Getting edit token');

$.ajax({ type: 'GET',  url: mw.util.wikiScript('api'),  data: {    format: 'json',    formatversion: 2,    action: 'query',    meta: 'tokens',    title: 'tokens'  },  dataType: 'json',  async: false,  success: function(response) {    editToken = response.query.tokens.csrftoken;  },  error: function(xhr, textStatus, error){    console.log(xhr.statusText + '\n' + textStatus + '\n' + error);    alert('Error while getting edit token');    return;  } });

for(var a in pages) { $.ajax({   type: 'POST',    url: mw.util.wikiScript('api'),    data: {      format: 'json',      formatversion: 2,      action: 'edit',      title: pages[a],      text: output[a],      summary: 'See Category talk:Block renders',      bot: true,      minor: true,      recreate: true,      token: editToken    },    dataType: 'json',    async: false,    success: function {      success++;    },    error: function(xhr, textStatus, error) {      console.log(xhr.statusText + '\n' + textStatus + '\n' + error);      alert('Error while editing pages');      return;    }  }); }

console.log('Success rate: ' + success + '/' + pages.length); alert('Success rate: ' + success + '/' + pages.length);

}