사용자:기나ㅏㄴ/sagwan helper.js
보이기
< 사용자:기나ㅏㄴ
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.
// <nowiki>
$( function () {
var SAGWAN = {};
window.SAGWANHelper = SAGWAN;
SAGWAN.summary = ' - [[사용자:기나ㅏㄴ/sagwan helper|Sagwan Helper]]';
SAGWAN.setup = function () {
$('span.mw-editsection-bracket:first-child').each( function() {
try {
var sectionNumber = this.parentElement.childNodes[1].href.match( /section=((T-)?\d+)&veaction=edit|action=edit§ion=((T-)?\d+)/ )[1];
var totalname = this.parentElement.childNodes[1].href.match(/title=([^&]+)/)[1];
this.after( '\) | ' );
$(this).after( $( '<a href="/w/index.php?title=' + totalname + '" class="SAGWANHelper-add-ncomment" section=' + sectionNumber + '>답변</a>') );
this.after( ' \(' );
$(this).after( $( '<a href="/w/index.php?title=' + totalname + '" class="SAGWANHelper-mark-not-done" section=' + sectionNumber + '>미완료</a>') );
this.after( '\) | ' );
$(this).after( $( '<a href="/w/index.php?title=' + totalname + '" class="SAGWANHelper-add-scomment" section=' + sectionNumber + '>답변</a>') );
this.after( ' \(' );
$(this).after( $( '<a href="/w/index.php?title=' + totalname + '" class="SAGWANHelper-mark-semi" section=' + sectionNumber + '>일부 완료</a>') );
this.after( '\) | ' );
$(this).after( $( '<a href="/w/index.php?title=' + totalname + '" class="SAGWANHelper-add-dcomment" section=' + sectionNumber + '>답변</a>') );
this.after( ' \(' );
$(this).after( $( '<a href="/w/index.php?title=' + totalname + '" class="SAGWANHelper-mark-done" section=' + sectionNumber + '>완료</a>') );
} catch ( e ) {
console.log(e);
}
} );
$('a.SAGWANHelper-mark-done').click( function(e) {
e.preventDefault();
console.log( this );
SAGWAN.doEdit( this, '{{완료}}', '완료' );
} );
$('a.SAGWANHelper-mark-not-done').click( function(e) {
e.preventDefault();
console.log( this );
SAGWAN.doEdit( this, '{{미완료}}', '미완료' );
} );
$('a.SAGWANHelper-add-dcomment').click( function(e) {
e.preventDefault();
console.log( this );
var commentText = window.prompt( '답변을 입력하십시오.' );
if ( commentText !== null ) {
SAGWAN.doEdit( this, '{{완료}} ' + commentText, '완료, 답변 추가' );
}
} );
$('a.SAGWANHelper-add-scomment').click( function(e) {
e.preventDefault();
console.log( this );
var commentText = window.prompt( '답변을 입력하십시오.' );
if ( commentText !== null ) {
SAGWAN.doEdit( this, '{{일부 완료}} ' + commentText, '일부 완료, 답변 추가' );
}
} );
$('a.SAGWANHelper-add-ncomment').click( function(e) {
e.preventDefault();
console.log( this );
var commentText = window.prompt( '답변을 입력하십시오.' );
if ( commentText !== null ) {
SAGWAN.doEdit( this, '{{미완료}} ' + commentText, '미완료, 답변 추가' );
}
} );
$('a.SAGWANHelper-mark-semi').click( function(e) {
e.preventDefault();
console.log( this );
SAGWAN.doEdit( this, '{{일부 완료}}', '일부 완료' );
} );
};
SAGWAN.doEdit = function ( section, comment, editSummary) {
console.log( section, comment, editSummary);
var sectionNumber = $(section).attr("section");
var pageTitle = mw.config.get( 'wgPageName' );
if(pageTitle==='위키백과:사용자_관리_요청'||pageTitle==='위키백과:문서_관리_요청'){
//console.log( section.outerHTML );
pageTitle = decodeURIComponent(section.outerHTML.match(/title=([^" ]+)/)[1]);
}
console.log( sectionNumber );
new mw.Api().get( {
action: 'parse',
page: pageTitle,
prop: 'wikitext',
section: sectionNumber
}).done( function( result ) {
console.log( result );
var wikitext = result.parse.wikitext['*'];
wikitext = wikitext + '\n:' + comment + ' ~~~~';
console.log( wikitext );
new mw.Api().postWithEditToken( {
action: 'edit',
title: pageTitle,
section: sectionNumber,
text: wikitext,
summary: editSummary + SAGWAN.summary,
minor: true,
nocreate: true
}).done( function( result ) {
console.log( result );
if ( result && result.edit && result.edit.result && result.edit.result === 'Success' ){
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then(function () {
location.reload();
});
}
});
});
};
} );
mw.loader.using( 'mediawiki.api', function() {
$(document).ready( function () {
if ( mw.config.get('wgAction') === 'view' && (
mw.config.get('wgPageName').includes('사용자_관리_요청') ||
mw.config.get('wgPageName').includes('문서_관리_요청')
) &&
mw.config.get('wgUserGroups').includes('sysop')
) {
window.SAGWANHelper.setup();
}
});
} );
// </nowiki>