Jump to content

User:Technical 13/SandBox/Section edit.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 19:28, 17 September 2013 (Nothing special...). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* GLOBAL */
console.group();
var pageTitle = mw.config.get('wgPageName');
var pageID = 0;
var pageCurrText = "";
getPageText()
console.groupEnd();
/* GLOBAL */

function jqEsc(expression) {
    return expression.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&');
}
 
function getSectionText() {
console.group();
	return $.ajax({
		url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') 
		+ '/api.php?action=query&format=json&indexpageids=true&prop=revisions&rvprop=content' + 
		+ '&section=' + sectionID + '&titles=' + pageTitle,
		dataType: 'json',
		success: function(response){
			pageID = response.query.pageids[0];
			pageCurrText = response.query.pages[pageID].revisions[0]['*'];
			console.info('Page ID: %d contains:\n%s', pageID, pageCurrText)
		},
		error: function(response){
			console.warn('Failed:\n%s', response);
		}
	});
	.done(){
		console.log('Passed: ')
	}
	.fail(){
		console.warn('Failed: ')
	}
console.groupEnd();
}