Jump to content

User:Qwerfjkl/scripts/massUndo.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(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#Category:Austro-Hungarian films]]",
		}).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]['*']);
	}
} );
	
	
});