User:Irukaza/js/editConflict.js:修订间差异
跳到导航
跳到搜索
imported>=海豚= (清空页面) |
imported>=海豚= 无编辑摘要 |
||
| 第1行: | 第1行: | ||
(async () => { | |||
if (!["edit", "submit"].includes(mw.config.get("wgAction"))) { | |||
} | |||
await mw.loader.using("mw.Api"); | |||
mw.loader.using('mediawiki.notification'); | |||
const wgPageName = mw.config.get("wgPageName"); | |||
const wgCurRevisionId = mw.config.get("wgCurRevisionId"); | |||
let needCheckFlag = true; | |||
const api = new mw.Api({ timeout: 5000 }); | |||
const wpSave = $("#wpSave"); | |||
const editform = $("#editform"); | |||
const SYMBOL_UNDEFINED = Symbol("SYMBOL_UNDEFINED"); | |||
wpSave.val = (value = SYMBOL_UNDEFINED) => { | |||
const val = $.fn.val.bind(wpSave); | |||
return value === SYMBOL_UNDEFINED ? val() : val(value).attr("title", value); | |||
}; | |||
const disable = ($buttons) => { | |||
return $buttons.css("font-weight", "normal").parent().removeClass("oo-ui-widget-enabled oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive").addClass("oo-ui-widget-disabled"); | |||
} | |||
wpSave.on("click", () => { | |||
if (needCheckFlag === true) { | |||
needCheckFlag = false; | |||
setTimeout(async () => { | |||
disable(wpSave.attr("disabled", "disabled").val("正在保存...")); | |||
for (let i = 1; i <= 4; i++) { | |||
try { | |||
const result = await api.post({ | |||
action: "query", | |||
prop: "revisions", | |||
rvprop: "ids", | |||
rvlimit: 1, | |||
titles: wgPageName, | |||
}); | |||
const pageid = Object.keys(result.query.pages)[0]; | |||
if (pageid > 0 && result.query.pages[pageid].revisions[0].revid > wgCurRevisionId) { | |||
wpSave.val("保存失败"); | |||
const pre = $("<pre/>", { | |||
css: { | |||
position: "absolute", | |||
left: "-99999px", | |||
"z-index": "-99999", | |||
}3 | |||
}); | |||
const textarea = $("#wpTextbox1"); | |||
$("#copyCurrentRawCode").on("click", async () => { | |||
await mw.loader.using('mediawiki.notification'); | |||
$("#mw-notification-area").css({ | |||
position: "fixed", | |||
top: 0, | |||
}).appendTo("body"); | |||
if ($(".ace_editor").length > 0) { | |||
} | |||
const selection = window.getSelection(); | |||
const rangeCount = selection.rangeCount; | |||
let range; | |||
if (rangeCount > 0) { | |||
range = selection.getRangeAt(0); | |||
} | |||
pre.text(textarea.val()); | |||
selection.selectAllChildren(pre[0]); | |||
document.execCommand("copy"); | |||
window.setTimeout(function() { | |||
selection.removeAllRanges(); | |||
if (rangeCount > 0) { | |||
selection.addRange(range); | |||
} | |||
pre.empty(); | |||
}, 0); | |||
mw.notify("复制成功!"); | |||
}); | |||
$("#showNewestRevisionDiff").on("click", () => { | |||
window.open(`${mw.config.get("wgServer")}${mw.config.get("wgScriptPath")}/index.php?diff=${result.query.pages[pageid].revisions[0].revid}`, "_blank").focus(); | |||
}); | |||
$("#refreshPage").on("click", () => { | |||
if (confirm("您是否已经复制好您的编辑内容?\n刷新后原来的编辑内容将会被最新版本的源码替换!\n点击确定将会刷新页面!!")) { | |||
location.reload(false); | |||
} | |||
}); | |||
disable($("#wpPreview, #wpDiff").on("click", () => { | |||
setTimeout(() => { | |||
alert(conflictAlert); | |||
}, 1); | |||
}).attr("title", conflictAlert)); | |||
} else { | |||
wpSave.val("正在保存..."); | |||
editform.submit(); | |||
} | |||
await mw.loader.using('mediawiki.notification'); | |||
} catch (e) { | |||
console.error("editConflict", e); | |||
wpSave.val(i <= 3 ? `编辑冲突检查失败,正在重试(第${i}次)……` : "编辑冲突检查失败,请稍后重试……"); | |||
} | |||
} | |||
setTimeout(() => { | |||
needCheckFlag = true; | |||
wpSave.removeAttr("disabled").val("保存更改").css("font-weight", "700").parent().addClass("oo-ui-widget-enabled oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive").removeClass("oo-ui-widget-disabled"); | |||
}, 2000); | |||
}, 1); | |||
} | |||
}); | |||
})(); | |||
2021年2月24日 (三) 10:28的版本
(async () => {
if (!["edit", "submit"].includes(mw.config.get("wgAction"))) {
}
await mw.loader.using("mw.Api");
mw.loader.using('mediawiki.notification');
const wgPageName = mw.config.get("wgPageName");
const wgCurRevisionId = mw.config.get("wgCurRevisionId");
let needCheckFlag = true;
const api = new mw.Api({ timeout: 5000 });
const wpSave = $("#wpSave");
const editform = $("#editform");
const SYMBOL_UNDEFINED = Symbol("SYMBOL_UNDEFINED");
wpSave.val = (value = SYMBOL_UNDEFINED) => {
const val = $.fn.val.bind(wpSave);
return value === SYMBOL_UNDEFINED ? val() : val(value).attr("title", value);
};
const disable = ($buttons) => {
return $buttons.css("font-weight", "normal").parent().removeClass("oo-ui-widget-enabled oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive").addClass("oo-ui-widget-disabled");
}
wpSave.on("click", () => {
if (needCheckFlag === true) {
needCheckFlag = false;
setTimeout(async () => {
disable(wpSave.attr("disabled", "disabled").val("正在保存..."));
for (let i = 1; i <= 4; i++) {
try {
const result = await api.post({
action: "query",
prop: "revisions",
rvprop: "ids",
rvlimit: 1,
titles: wgPageName,
});
const pageid = Object.keys(result.query.pages)[0];
if (pageid > 0 && result.query.pages[pageid].revisions[0].revid > wgCurRevisionId) {
wpSave.val("保存失败");
const pre = $("<pre/>", {
css: {
position: "absolute",
left: "-99999px",
"z-index": "-99999",
}3
});
const textarea = $("#wpTextbox1");
$("#copyCurrentRawCode").on("click", async () => {
await mw.loader.using('mediawiki.notification');
$("#mw-notification-area").css({
position: "fixed",
top: 0,
}).appendTo("body");
if ($(".ace_editor").length > 0) {
}
const selection = window.getSelection();
const rangeCount = selection.rangeCount;
let range;
if (rangeCount > 0) {
range = selection.getRangeAt(0);
}
pre.text(textarea.val());
selection.selectAllChildren(pre[0]);
document.execCommand("copy");
window.setTimeout(function() {
selection.removeAllRanges();
if (rangeCount > 0) {
selection.addRange(range);
}
pre.empty();
}, 0);
mw.notify("复制成功!");
});
$("#showNewestRevisionDiff").on("click", () => {
window.open(`${mw.config.get("wgServer")}${mw.config.get("wgScriptPath")}/index.php?diff=${result.query.pages[pageid].revisions[0].revid}`, "_blank").focus();
});
$("#refreshPage").on("click", () => {
if (confirm("您是否已经复制好您的编辑内容?\n刷新后原来的编辑内容将会被最新版本的源码替换!\n点击确定将会刷新页面!!")) {
location.reload(false);
}
});
disable($("#wpPreview, #wpDiff").on("click", () => {
setTimeout(() => {
alert(conflictAlert);
}, 1);
}).attr("title", conflictAlert));
} else {
wpSave.val("正在保存...");
editform.submit();
}
await mw.loader.using('mediawiki.notification');
} catch (e) {
console.error("editConflict", e);
wpSave.val(i <= 3 ? `编辑冲突检查失败,正在重试(第${i}次)……` : "编辑冲突检查失败,请稍后重试……");
}
}
setTimeout(() => {
needCheckFlag = true;
wpSave.removeAttr("disabled").val("保存更改").css("font-weight", "700").parent().addClass("oo-ui-widget-enabled oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive").removeClass("oo-ui-widget-disabled");
}, 2000);
}, 1);
}
});
})();