User:DannyS712 test/undo.js

// Install with: // // or with //  // // If forking this script, please note my contributions / give me credit // $(function { var EC_config = {	name: 'Force EC.js',	version: 1.0,	debug: false }; var url = window.location.href; console.log( url ); if (url.indexOf('action=history') > -1){	if (location.search.includes('action=history')) {		var parent_ids = document.querySelectorAll('li[data-mw-revid]');		var revid, rev_user, links;		for (var iii = 0; iii < parent_ids.length; iii++) {			revid = parent_ids[iii].getAttribute('data-mw-revid');			if (revid && revid != mw.config.get('wgCurRevisionId')) {				rev_user = parent_ids[iii].getElementsByClassName('history-user')[0].getElementsByTagName('a')[0].getAttribute('title').replace('User:','');				var params = $.param({ title: mw.config.get('wgPageName'), action: 'submit', summary: 'Partially undo edits starting from revision ' + revid, from_old: revid });				links = parent_ids[iii].getElementsByClassName('mw-changeslist-links');				links[links.length - 1].innerHTML += ' Partially undo ';			}		}	} } else if (url.indexOf('submit') > -1 && url.indexOf('from_old') > -1){	var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';	var revid = url.replace(/.*from_old=/, '');	var old_content = get_page( revid );	var initial_content = 'LEAVE THIS LINE ALONE, IT FORCES THE EDIT CONFLIC' + old_content.replace(/=\n/g, '=\n') + '\nLEAVE THIS LINE ALONE, IT FORCES THE EDIT CONFLIC';	var old_time = get_rev( revid );	console.log( revid, old_time );	$('input[name=wpStarttime]').val(old_time);	$('input[name=wpEdittime]').val(old_time);	$('input[name=editRevId]').val(revid);	$('input[name=baseRevId]').val(revid);	$('input[name=parentRevId]').val(revid);	$('#wpTextbox1').val(initial_content); } function get_page( old_id ){ var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php'; console.log( old_id ); var page_to_get = { action: 'parse', oldid: old_id, prop: 'wikitext', format: 'json', formatversion: 2 };   var result = null; $.ajax({		url: scriptUrl,		type: 'get',		data: page_to_get,		dataType: 'json',		async: false,		success: function(page) {			console.log( page );			var text = page.parse.wikitext;			//console.log( text );			result = text;		} 	}); return result; } function get_rev( rev ){ var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php'; console.log( rev ); var rev_to_get = { action: 'query', prop: 'revisions', titles: mw.config.get('wgPageName'), rvprop: 'timestamp', rvstartid: rev, rvlimit: 1, format: 'json', formatversion: 2 };   var result = null; $.ajax({		url: scriptUrl,		type: 'get',		data: rev_to_get,		dataType: 'json',		async: false,		success: function(rev_info) {			console.log( rev_info );			var rev_time = rev_info.query.pages[0].revisions[0].timestamp.replace(/[^0-9]/g, '');			console.log( rev_time );			result = rev_time;		} 	}); return result; } }); //