MediaWiki:Gadget-Purge.js:修订间差异
跳转到导航
跳转到搜索
小 // Edit via InPageEdit 标签:已被回退 |
小 // Edit via InPageEdit 标签:已被回退 |
||
第5行: | 第5行: | ||
return; | return; | ||
} | } | ||
const $purgeButton = ( | const $purgeButton = ( | ||
buttonText = wgULS("清除页面缓存", "清除頁面快取"), | buttonText = wgULS("清除页面缓存", "清除頁面快取"), | ||
purgingText = wgULS("正在清除缓存", "正在清除快取"), | purgingText = wgULS("正在清除缓存", "正在清除快取"), | ||
succesText = wgULS("清除缓存成功!", "清除快取成功!"), | succesText = wgULS("清除缓存成功!", "清除快取成功!"), | ||
failText = wgULS("清除缓存失败,点击可重试", "清除快取失敗,點選可重試", null, null, "清除快取失敗,點擊可重試") | failText = wgULS("清除缓存失败,点击可重试", "清除快取失敗,點選可重試", null, null, "清除快取失敗,點擊可重試") | ||
) => { | ) => { | ||
const $statusNode = $('<span class="n-button__content" />').text(buttonText); | const $statusNode = $('<span class="n-button__content" />').text(buttonText); | ||
第22行: | 第23行: | ||
$statusNode.prepend('<img src="https://vj-wiki.top/images/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">'); | $statusNode.prepend('<img src="https://vj-wiki.top/images/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">'); | ||
runningStatus = true; | runningStatus = true; | ||
const api = new mw.Api() | |||
const api = new mw.Api(); | |||
const opt = { | |||
action: "purge", | |||
format: "json", | |||
forcelinkupdate: true, | |||
titles: mw.config.get("wgPageName"), | |||
}; | |||
try { | try { | ||
await api.post(opt); | await api.post(opt); |
2025年9月14日 (日) 08:21的版本
"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();
const 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(e) {
$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>