MediaWiki:Gadget-Purge.js:修订间差异
跳转到导航
跳转到搜索
小无编辑摘要 |
小 引自萌娘百科,无需二次确认 // Edit via InPageEdit 标签:已被回退 |
||
第1行: | 第1行: | ||
"use strict"; | |||
// <pre> | |||
$(() => { | |||
if (!mw.config.get("wgIsArticle")) { | |||
return; | |||
} | } | ||
})( | const $purgeButton = ( | ||
buttonText = wgULS("清除页面缓存", "清除頁面快取"), | |||
purgingText = wgULS("正在清除缓存", "正在清除快取"), | |||
succesText = wgULS("清除缓存成功!", "清除快取成功!"), | |||
failText = wgULS("清除缓存失败,点击可重试", "清除快取失敗,點選可重試", null, null, "清除快取失敗,點擊可重試"), | |||
) => { | |||
const $statusNode = $('<span class="n-button__content" />').text(buttonText); | |||
const $containerNode = $('<a class="n-button purgecache" />').append($statusNode); | |||
let runningStatus = false; | |||
$containerNode.on("click", async () => { | |||
if (runningStatus) { | |||
return; | |||
} | |||
$statusNode.text(purgingText); | |||
$statusNode.prepend('<img src="https://vj-wiki.top/images/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">'); | |||
runningStatus = true; | |||
const api = new mw.Api(), | |||
opt = { | |||
action: "purge", | |||
format: "json", | |||
forcelinkupdate: true, | |||
titles: mw.config.get("wgPageName"), | |||
}; | |||
try { | |||
await api.post(opt); | |||
$statusNode.text(succesText); | |||
setTimeout(() => location.reload(location, true), 200); | |||
} catch { | |||
$statusNode.text(failText); | |||
// eslint-disable-next-line require-atomic-updates | |||
runningStatus = false; | |||
setTimeout(() => { | |||
if (!runningStatus) { | |||
$statusNode.text(buttonText); | |||
} | |||
}, 5000); | |||
} | |||
}); | |||
return $containerNode; | |||
}; | |||
$("#p-cactions ul").append( | |||
$('<li class="mw-list-item mw-list-item-js" id="pt-purge" />').append($purgeButton()) | |||
); | |||
}); | |||
// </pre> |
2025年9月14日 (日) 08:14的版本
"use strict";
// <pre>
$(() => {
if (!mw.config.get("wgIsArticle")) {
return;
}
const $purgeButton = (
buttonText = wgULS("清除页面缓存", "清除頁面快取"),
purgingText = wgULS("正在清除缓存", "正在清除快取"),
succesText = wgULS("清除缓存成功!", "清除快取成功!"),
failText = wgULS("清除缓存失败,点击可重试", "清除快取失敗,點選可重試", null, null, "清除快取失敗,點擊可重試"),
) => {
const $statusNode = $('<span class="n-button__content" />').text(buttonText);
const $containerNode = $('<a class="n-button purgecache" />').append($statusNode);
let runningStatus = false;
$containerNode.on("click", async () => {
if (runningStatus) {
return;
}
$statusNode.text(purgingText);
$statusNode.prepend('<img src="https://vj-wiki.top/images/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">');
runningStatus = true;
const api = new mw.Api(),
opt = {
action: "purge",
format: "json",
forcelinkupdate: true,
titles: mw.config.get("wgPageName"),
};
try {
await api.post(opt);
$statusNode.text(succesText);
setTimeout(() => location.reload(location, true), 200);
} catch {
$statusNode.text(failText);
// eslint-disable-next-line require-atomic-updates
runningStatus = false;
setTimeout(() => {
if (!runningStatus) {
$statusNode.text(buttonText);
}
}, 5000);
}
});
return $containerNode;
};
$("#p-cactions ul").append(
$('<li class="mw-list-item mw-list-item-js" id="pt-purge" />').append($purgeButton())
);
});
// </pre>