/*
* insituUndo - 取り消しを履歴ページ内で完結させるスクリプト
* Author - User:鈴音雨
*/
(function () {
function init() {
var $undoLinks = $(".mw-history-undo a, .mw-diff-undo a");
$undoLinks.each(function () {
var $this = $(this);
var href = $this.attr("href");
$this.on("click", function (e) {
e.preventDefault();
var c = prompt("コメントを入力してください");
if (c === null) {
return;
}
var $parent = $this.parent();
$this.css("display", "none");
var $spinner = $("<img src='//upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif' alt='loading' class='insitu-undo-spinner' />");
$parent.append($spinner);
$parent.append("<span>取り消し中...</span>");
var undo = href.match(/&undo=(\d+)/)[1];
var undoafter = href.match(/&undoafter=(\d+)/);
var api = new mw.Api();
api.postWithEditToken({
action: "edit",
title: mw.config.get("wgPageName"),
undo: undo,
undoafter: undoafter ? undoafter[1] : "",
summary: c || undefined,
}).done(function () {
$spinner.remove();
$parent.find("span").text("取り消しました");
$parent.css("background-color", "#86f8a6");
//$insituUndo.css("display", "inline");
}).fail(function (e) {
console.error(e);
$spinner.remove();
$parent.find("span").text("取り消しに失敗しました (" + e.toString() + ")");
$parent.css("background-color", "#ffad8f")
//$insituUndo.css("display", "inline");
});
});
});
}
mw.loader.using(["mediawiki.api", "mediawiki.util"], function () {
if (mw.config.get("wgAction") == "history" || location.href.includes("diff=")) {
init();
}
});
})();