User:BPositive/getPageContent.js

mw.loader.using( ['jquery.ui.dialog', 'mediawiki.api'], function {	function renderContentDialog ( content ) {		var $dialog = $( '  ' )			.text ( content )			.dialog ({ autoOpen: true, title: 'Revision before FuzzyBot\'s edit on ' + wgPageName, width: '70%', modal: true });	}   function getContent{	    var api_1 = new mw.Api;	    api_1.get ({ action:'query', prop: 'revisions', format: 'json', rvprop: 'timestamp', rvuser: 'FuzzyBot', titles: wgPageName }).done ( function( data ) { //FB = FuzzyBot if ( typeof data['query']['pages'][wgArticleId]['revisions'] === 'undefined' ) {	// variable is undefined renderContentDialog("No edit by FuzzyBot on this page"); }			else { var timestampFB = data['query']['pages'][wgArticleId]['revisions'][0]['timestamp']; console.log ( "Timestamp for FuzzyBot's revision: " + timestampFB ); var dateFB = new Date( timestampFB ); dateFB.setSeconds( dateFB.getSeconds - 1 ); var timestampOld = dateFB.toISOString; console.log( "New Timestamp: " + timestampOld ); var api_2 = new mw.Api; api_2.get ({			       action:'query',			        prop: 'revisions',			        format: 'json',			        rvprop: 'content',			        rvstart: timestampOld,			        titles: wgPageName			    }).done ( function( data ) {			    	//console.log("Revision before FuzzyBot's edit: " + data['query']['pages']['19563']['revisions'][0]['*']);			    	renderContentDialog(data['query']['pages'][wgArticleId]['revisions'][0]['*']);			    }); }	   });    }    $(document).ready( function { // Add a link to the toolbox var link = mw.util.addPortletLink(			'p-tb',			'#',			'Get content',			't-prettylinkwidget',			'Get revision before FuzzyBot\'s edit',			null,			'#t-whatlinkshere'		); $(link).click( function( e ) {			// Avoid the browser going to '#'			e.preventDefault;			getContent;		}); }); });