User:Extorc/rmMaster.js

function closeReq(info){ console.log("clicked close request button") var api = new mw.Api; api.postWithToken("csrf", {action: 'edit', title: info.title, appendtext: info.text, summary: info.summary, section: 2} ).done(function( data ) {		alert( 'Page edited!' );	} ).fail( function(code, data) {		console.log( api.getErrorMessage( data ).text);	} ); }

function doSomethingWithText( wikitext ) { console.log(wikitext); } function doSomethingInCaseOfError {console.log( 'err' );}

console.log("rmMaster init") $('.mw-heading').each( function(index){                       //Look for each section in the page		var $heading = $(this).find('span.mw-headline')        //Fetch for its text content		if($heading.text.trim.includes("Requested move")){ //If it contains the words Requested move, which supposedly all RMdiscs would then continue			console.log("found rmdisc")			$(this).append(" Close Request ")           //Append a test Button		}		else{			console.log($heading.text.trim)                //Otherwise print the content of the heading for debudding		}	} );

$('button').click(function{	var user = 'User:' + mw.config.get( 'wgUserName' );	closeReq({title: 'Wikipedia:Sandbox',text: 'Moved',summary: '' + user + ' closed request using rmCloser'});	$.getJSON(mw.util.wikiScript('api'), {format: 'json', action: 'query', prop: 'revisions', rvprop: 'content', rvlimit: 1, titles: 'Wikipedia:Sandbox'}).then(function ( data ) { var page, wikitext; try { for ( page in data.query.pages ) { wikitext = data.query.pages[page].revisions[0]['*']; doSomethingWithText( wikitext ); }		} catch ( e ) { doSomethingInCaseOfError; }	}).catch( doSomethingInCaseOfError ); })