MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 6: | Line 6: | ||
$(this).siblings(".text").toggle("slow"); | $(this).siblings(".text").toggle("slow"); | ||
}); | }); | ||
$("#start-edit-test").click(function(){ | |||
editPage("summary", "content", "159d15f2706c7140ac229e91474d142e57ed8df4+\\"); | |||
}); | |||
function editPage(summary, content, editToken ) { | |||
$.ajax({ | |||
url: 'https://wiki.factorio.com/api.php', | |||
data: { | |||
format: 'json', | |||
action: 'edit', | |||
title: 'User:TheWombatGuru/Sandbox/Auto_edit_test', | |||
section: 'new', | |||
summary: summary, | |||
text: content, | |||
token: editToken | |||
}, | |||
dataType: 'json', | |||
type: 'POST', | |||
success: function( data ) { | |||
if ( data && data.edit && data.edit.result == 'Success' ) { | |||
window.location.reload(); // reload page if edit was successful | |||
} else if ( data && data.error ) { | |||
alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info ); | |||
} else { | |||
alert( 'Error: Unknown result from API.' ); | |||
} | |||
}, | |||
error: function( xhr ) { | |||
alert( 'Error: Request failed.' ); | |||
} | |||
}); | |||
} |
Revision as of 22:06, 29 September 2016
/* Any JavaScript here will be loaded for all users on every page load. */
/*$(".navbox").css("background", "red");*/
//Spoiler template JavaScript
$(".spoiler-container .button").click(function() {
$(this).siblings(".text").toggle("slow");
});
$("#start-edit-test").click(function(){
editPage("summary", "content", "159d15f2706c7140ac229e91474d142e57ed8df4+\\");
});
function editPage(summary, content, editToken ) {
$.ajax({
url: 'https://wiki.factorio.com/api.php',
data: {
format: 'json',
action: 'edit',
title: 'User:TheWombatGuru/Sandbox/Auto_edit_test',
section: 'new',
summary: summary,
text: content,
token: editToken
},
dataType: 'json',
type: 'POST',
success: function( data ) {
if ( data && data.edit && data.edit.result == 'Success' ) {
window.location.reload(); // reload page if edit was successful
} else if ( data && data.error ) {
alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );
} else {
alert( 'Error: Unknown result from API.' );
}
},
error: function( xhr ) {
alert( 'Error: Request failed.' );
}
});
}