사용자:기나ㅏㄴ/test.js
보이기
< 사용자:기나ㅏㄴ
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.
// <nowiki>
$.when(
$.ready,
mw.loader.using(["mediawiki.util", "oojs-ui-core", "oojs-ui-widgets"])
).then(function () {
$("span.mw-headline").each(function () {
var popup = null;
$(this).after(" ", $("<a>", { "class": "copy-section-link-pilcrow" })
.text("[이동]")
.click(function () {
var hash = $(this).prev().attr("id"); // 문단명
var match = hash.match(/([^→]+)→([^→]+)/);
if (match) {
var moveFrom = match[1].trim();
var moveTo = match[2].trim();
createPopup(moveFrom, moveTo, this);
}
}));
});
mw.util.addCSS("h2 .copy-section-link-pilcrow," +
"h3 .copy-section-link-pilcrow," +
"h4 .copy-section-link-pilcrow," +
"h5 .copy-section-link-pilcrow," +
"h6 .copy-section-link-pilcrow" +
"{ display: none }" +
"h2:hover .copy-section-link-pilcrow," +
"h3:hover .copy-section-link-pilcrow," +
"h4:hover .copy-section-link-pilcrow," +
"h5:hover .copy-section-link-pilcrow," +
"h6:hover .copy-section-link-pilcrow" +
"{ display: inline }");
});
function createPopup(moveFrom, moveTo, element) {
var wikitext = (moveFrom + " → " + moveTo).replace(/_/g, " ");
var $popupContent = $('<div>').append(
$('<p>', { "class": "copy-section-link-content" }).append(
$("<code>").text(wikitext)
),
$("<button>", { "class": "oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement-button" })
.text("실행")
.click(function () {
movePage(moveFrom, moveTo);
})
);
var normalPanel = new OO.ui.TabPanelLayout('normal', {
label: '이동',
$content: $popupContent
});
var index = new OO.ui.IndexLayout();
index.addTabPanels([normalPanel]);
var popup = new OO.ui.PopupWidget({
$content: index.$element,
$floatableContainer: $(element),
padded: true,
width: 400,
height: 190,
align: 'forwards',
});
popup.toggle(true);
$(element).after(popup.$element);
}
function movePage(from, to) {
var token = mw.user.tokens.get('csrfToken');
var apiUrl = mw.util.wikiScript('api');
$.ajax({
url: apiUrl,
type: 'POST',
dataType: 'json',
data: {
action: 'move',
from: from,
to: to,
reason: 'Moving from ' + from + ' to ' + to,
movetalk: '1',
token: token
},
success: function (data) {
if (data && data.move && data.move.success) {
mw.notify('이동을 완료하였습니다.', { type: 'success' });
console.log('문서 이동이 완료되었습니다:', data);
} else {
mw.notify('이동에 실패하였습니다.', { type: 'warn' });
console.error('문서 이동 중 오류1이 발생했습니다:', data);
}
},
error: function (xhr, status, error) {
mw.notify('이동에 실패하였습니다.', { type: 'error' });
console.error('문서 이동 중 오류2가 발생했습니다:', error);
}
});
}
// </nowiki>