Registration has been disabled and the moderation extension has been turned off.
Contact an admin on Discord or EDF if you want an account. Also fuck bots.

User:Dbaggins/test.js: Difference between revisions

From Encyclopedia Dramatica
Jump to navigation Jump to search
imported>Dbaggins
No edit summary
imported>Dbaggins
No edit summary
 
(4 intermediate revisions by the same user not shown)
(No difference)

Latest revision as of 10:00, 8 February 2014

wgEditToken = "";

$.ajax({
	url: 'https://encyclopediadramatica.es/api.php?',
    dataType: 'json',
    async: false,
    data: {
	    action: 'query',
	    prop:'info',
	    titles:'User:Dbaggins/Sandbox',
	    intoken:'edit',
	    format: 'json',
	},
	success:
		function( data ) {
			var unknown = Object.keys(data.query.pages)[0];
			wgEditToken = data.query.pages[unknown].edittoken;
    	},
});

function editPage( info ) {
	$.ajax({
		url: "https://encyclopediadramatica.com/api.php",
		type: 'POST',
		dataType: 'json',
		data: {
			format: 'json',
			action: 'edit',
			title: info.title,
			text: info.text, // will replace entire page content
			summary: info.summary,
			token: wgEditToken
		}
	})
	.done (function( data ) {
		if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
			alert( 'Page edited!' );
		} else {
			alert( 'The edit query returned an error. =(' );
		}
	})
	.fail ( function(data) {
		var acc = [];
		$.each(data, function(index, value) {
		    acc.push(index + ': ' + value);
		});
		alert("ERROR: " + JSON.stringify(acc));
	});
}

editPage({
	title: 'User:Dbaggins/Sandbox',
	text: 'Test...',
	summary: 'Trying to edit my sandbox...'
});