User:BPositive/prepare.js

mw.loader.using( ['jquery.ui.dialog', 'mediawiki.api'], function {	//Function to show the content in a dialog box	function renderContentDialog ( content ) {		var $dialog = $( '  ' )			.html ( content )			.dialog ({ autoOpen: true, title: 'Text after preparing the page ' + wgPageName + " for translation", width: '70%', modal: true });	}	function addLanguageBar(pageContent){		//&lt; and &gt; are just for display purpose. Will be substituded with    	pageContent = "&lt;languages/&gt;\n" + pageContent.replace(/+/gi, "");    	console.log(pageContent);    	//regexp = +    	return pageContent;    }	///w/api.php?action=query&prop=revisions&format=json&rvprop=content&rvlimit=1&titles=User%3ABPositive	//Function to prepare the page for translation    function prepareForTranslation{	    var api = new mw.Api;	    //This api call returns the raw source text of the page	    api.get ({ action:'query', prop: 'revisions', format: 'json', rvprop: 'content', rvlimit: '1', titles: wgPageName }).done ( function( data ) { var pageContent = data['query']['pages'][wgArticleId]['revisions'][0]['*']; //pageContent.replace('\\n', ' '); pageContent = addLanguageBar(pageContent); renderContentDialog(pageContent); });   }    $(document).ready( function { // Add a link to the toolbox var link = mw.util.addPortletLink(			'p-tb',			'#',			'Prepare',			't-preparetranslation',			'Prepare the page for translation',			null,			'#t-whatlinkshere'		); $(link).click( function( e ) {			// Avoid the browser going to '#'			e.preventDefault;			prepareForTranslation;		}); }); });