User:Qwerfjkl/scripts/massUndo.js

$(function {	function undo(undoId, title) {		return new mw.Api.postWithEditToken({ action: 'edit', undo: undoId, title: title, bot: true, summary: "Undoing Qwerfjkl (bot)'s edits per User talk:Qwerfjkl", }).then( function { listPage(title) },			function(_, data) { mw.notify(new mw.Api.getErrorMessage(data), {type: 'error'}); }		);	}	function parseData(data) {		alert(data)		data = JSON.parse(data)		data = data['rows']		handleMassEdit(data)	}	function listPage( title ) {	var api = new mw.Api;	api.postWithToken("csrf", { action: 'edit', bot: true, title: 'User:Qwerfjkl/sandbox/CountryCatPages', append: '\n* '+title+'', summary: "Add "+title } ).done(function( data ) { console.log('Logged '+title) } ).fail( function(code, data) { console.log( api.getErrorMessage( data ).text); })	}	function handleMassEdit(data) {		jQuery.each(data, function(i, val) { undo(val[0], val[3]) })	} (new mw.Api).get( { prop: 'revisions', rvprop: 'content', rvlimit: 1, indexpageids: true, titles: 'User:Qwerfjkl/scripts/massUndo.js/data.json' } ) .then( function ( data ) { var q = data.query, id = q && q.pageids && q.pageids[0], pg = id && q.pages && q.pages[ id ], rv = pg && pg.revisions; if ( rv && rv[0] && rv[0]['*'] ) { parseData(rv[0]['*']); } } ); });