User:SSethi (WMF)/common.js

/* Work in progress for a user script aimed at emailing users on a specific MW page */

//Step 1 Fetch wikitext from a page mw.loader.using(['mediawiki.util', 'mediawiki.api'], function {	$(document).ready(function{ (new mw.Api).get( {			prop: 'revisions',			rvprop: 'content',			format: 'json',			rvlimit: 1,			indexpageids: true,			titles: 'User:SSethi_(WMF)/Sandbox'		} ) .done( function ( data ) {			//console.log(JSON.stringify(data, null, 4));			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]['*'] ) {				collectUserPages( rv[0]['*'] );			}		} ) .fail( showError ); }); 	function collectUserPages(userPages) {		var regex = '/(User:[0-9A-Z].+)/g';		console.log( "regex is : " + regex );		console.log(userPages);		console.log(userPages.match(regex));		//console.log(mw.user.tokens.get( 'emailToken' ));		//alert(userPages);	}	function showError {		alert( "An error occured while fetching wikitext of the page you requested" );	} });