注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
?_=1
来访问最新页面。https://zh.moegirl.org.cn/User:AnnAngela/js/floatPurgeButton.js?_=1
/* eslint-disable require-atomic-updates */ // <pre> "use strict"; $(() => (async () => { if (mw.config.get("wgNamespaceNumber") < 0 || mw.config.get("wgPageContentModel") !== "wikitext") { return; } await mw.loader.using("mediawiki.api"); const api = new mw.Api(); const opt = { action: "purge", format: "json", forcelinkupdate: true, titles: mw.config.get("wgPageName"), }; const body = document.body, html = document.documentElement; const innerWidth = window.innerWidth; let scrollbarWidth; switch ("scroll") { case getComputedStyle(body).overflowY: scrollbarWidth = innerWidth - body.clientWidth; break; case getComputedStyle(html).overflowY: scrollbarWidth = innerWidth - html.clientWidth; break; default: { const backup = body.style.overflowY; body.style.overflowY = "scroll"; scrollbarWidth = innerWidth - body.clientWidth; body.style.overflowY = backup; } } let runningStatus = false; const statusNode = $("<div/>", { text: "清除缓存", attr: { title: "清除缓存", }, id: "floatPurgeButton", css: { width: "20px", padding: "5px 0", "font-size": "12px", "background-color": "#000", color: "#fff", "font-size": "12px", "text-align": "center", position: "fixed", right: "0", bottom: "0", cursor: "pointer", opacity: ".6", "z-index": "73", "user-select": "none", display: "block", }, on: { click: async () => { if (runningStatus) { return; } statusNode.text("清除中①"); runningStatus = true; let actionID = 0; try { actionID = 1; await api.post(opt); await new Promise((res) => setTimeout(res, 185)); statusNode.text("清除中②"); await new Promise((res) => setTimeout(res, 185)); actionID = 2; await api.post(opt); statusNode.text("清除成功"); setTimeout(location.reload.bind(location), 1000); } catch (e) { console.error(`Action ${actionID} failed:`, e); runningStatus = false; statusNode.text("清除失败"); setTimeout(() => { if (!runningStatus) { statusNode.text("清除缓存"); } }, 5000); } }, }, }).appendTo($(document.body).append("<style>@media print{#floatPurgeButton{display:none!important}}</style>")); if (scrollbarWidth === 0) { statusNode.css("right", "20px"); // 修复新版 Chrome 的自动隐藏式滚动条导致的按钮被覆盖 chrome://flags/#overlay-scrollbars } })()); // </pre>