사용자:BANIP/common.js: 두 판 사이의 차이
백괴게임>BANIP 잔글편집 요약 없음 |
백괴게임>BANIP 잔글편집 요약 없음 |
||
36번째 줄: | 36번째 줄: | ||
} | } | ||
function addDocument( title, summary, content, editToken ){ | function addDocument( title, summary, content, editToken ){ | ||
originContent = getDocument(title) | |||
changeDocument( title, summary, originContent + content, editToken ); | |||
} | |||
function getDocument(title){ | |||
var originContent; | var originContent; | ||
$.ajax({ | $.ajax({ | ||
44번째 줄: | 49번째 줄: | ||
async: false | async: false | ||
}) | }) | ||
return originContent; | |||
} | } |
2017년 5월 18일 (목) 11:10 판
var token;
$.ajax({
url:"/w/api.php?action=query&meta=tokens",
success:function(v,i){
var datas = JSON.parse($(v).find("pre").text());
console.log(datas["query"]["tokens"]["csrftoken"]);
token = datas["query"]["tokens"]["csrftoken"];
}
})
function changeDocument( title, summary, content, editToken ) {
$.ajax({
url: mw.util.wikiScript("api"),
data: {
format: 'json',
action: 'edit',
title: title,
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.' );
}
});
}
function addDocument( title, summary, content, editToken ){
originContent = getDocument(title)
changeDocument( title, summary, originContent + content, editToken );
}
function getDocument(title){
var originContent;
$.ajax({
url:"/w/index.php?title=" + title + "&action=edit",
success:function ajaxSucess(data){
originContent = $(data).find("textarea").html();
},
async: false
})
return originContent;
}