사용자:BANIP/common.js: 두 판 사이의 차이
백괴게임>BANIP 잔글편집 요약 없음 |
백괴게임>BANIP 잔글편집 요약 없음 |
||
53번째 줄: | 53번째 줄: | ||
}) | }) | ||
return originContent; | return originContent; | ||
} | |||
function readDocument(title){ | |||
var doc; | |||
$.ajax({ | |||
url:"/wiki/" + title, | |||
success:function ajaxSucess(data){ | |||
doc = $(data).find("#mw-content-text"); | |||
}, | |||
async: false | |||
}) | |||
return doc; | |||
} | } | ||
if( $(".use-script").length >= 1 ){ | if( $(".use-script").length >= 1 ){ | ||
let $doc = $("#mw-content-text"); | let $doc = $("##mw-content-text"); | ||
let setupMeta = readDocument("틀:플러그인/setup"); | let setupMeta = readDocument("틀:플러그인/setup"); | ||
$doc.html(setupMeta); | $doc.html(setupMeta); | ||
} | } |
2017년 5월 18일 (목) 11:27 판
//토큰 수집
var plugins = {}
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;
}
function readDocument(title){
var doc;
$.ajax({
url:"/wiki/" + title,
success:function ajaxSucess(data){
doc = $(data).find("#mw-content-text");
},
async: false
})
return doc;
}
if( $(".use-script").length >= 1 ){
let $doc = $("##mw-content-text");
let setupMeta = readDocument("틀:플러그인/setup");
$doc.html(setupMeta);
}