2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

User:AnnAngela/js/floatPurgeButton.js

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存
如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码?_=1来访问最新页面。
添加代码后的本页地址如下:-{R|https://moegirl.icu/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>