Jump to content

User:DannyS712 test/page.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DannyS712 test (talk | contribs) at 07:06, 23 February 2019 (tweak, for reuse). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
//<nowiki>
$(function (){
var pg_config = {
	name: '[[User:DannyS712/page|page.js]]',
	version: 1.0,
	debug: true
};
var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';
function get_page( name ){
    var page_to_get = {
        action: 'query',
        titles: name,
        prop: 'revisions',
        rvprop: 'content',
        format: 'json',
        formatversion: 2
    };
    var result = null;
	$.ajax({
		url: scriptUrl,
		type: 'get',
		data: page_to_get,
		dataType: 'json',
		async: false,
		success: function(page) {
			if (pg_config.debug) console.log( page );
	    	result = page.query.pages["0"].revisions["0"].content;
	    	if (pg_config.debug) console.log( result );
		} 
	});
	return result;
}
function set_new ( page, new_content ){
	console.log( page, new_content );
    var to_send = {
        action: 'edit',
        title: page,
        text: new_content,
        minor: true,
        summary: pg_summary,
        token: mw.user.tokens.get( 'editToken' )
    };
    console.log( to_send );
    $.when(
        $.post( scriptUrl, to_send, function( response ){ } )
    ).done( function() {
		location.reload();
    } );
}
});
//</nowiki>