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

User:AnnAngela/js/watchScripts.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/watchScripts.js?_=1}-
// <pre>
"use strict";
$(() => (async () => {
    await mw.loader.using(["mediawiki.api", "ext.gadget.LocalObjectStorage", "mediawiki.user"]);
    const localObjectStorage = new LocalObjectStorage("watchScripts");
    const lastTime = localObjectStorage.getItem("lastUpdate", -1);
    const now = Date.now();
    if (typeof lastTime === "number" && now - lastTime < 86400000) {
        return;
    }
    localObjectStorage.setItem("lastUpdate", now);
    const api = new mw.Api();
    const existWatchlist = await (async () => {
        const result = [];
        let wrcontinue;
        while (Number.MAX_SAFE_INTEGER > Number.MIN_SAFE_INTEGER) {
            const r = await api.post({
                action: "query",
                list: "watchlistraw",
                wrnamespace: "8|274",
                wrlimit: "max",
                wrcontinue,
            });
            for (const { ns, title } of r.watchlistraw) {
                if (ns === 274 || /\.(?:j|cs)s$/.test(title)) {
                    result.push(title);
                }
            }
            if (r.continue) {
                wrcontinue = r.continue.wrcontinue;
            } else {
                break;
            }
        }
        return result;
    })();
    const scriptPages = await (async () => {
        const result = [];
        let apcontinue;
        while (Number.MAX_SAFE_INTEGER > Number.MIN_SAFE_INTEGER) {
            const r = await api.post({
                action: "query",
                list: "allpages",
                apnamespace: "8",
                aplimit: "max",
                apcontinue,
            });
            for (const { title } of r.query.allpages) {
                if (/\.(?:j|cs)s$/.test(title)) {
                    result.push(title);
                }
            }
            if (r.continue) {
                apcontinue = r.continue.apcontinue;
            } else {
                break;
            }
        }
        apcontinue = undefined;
        while (Number.MAX_SAFE_INTEGER > Number.MIN_SAFE_INTEGER) {
            const r = await api.post({
                action: "query",
                list: "allpages",
                apnamespace: "274",
                aplimit: "max",
                apcontinue,
            });
            for (const { title } of r.query.allpages) {
                result.push(title);
            }
            if (r.continue) {
                apcontinue = r.continue.apcontinue;
            } else {
                break;
            }
        }
        return result;
    })();
    const needToBeWatched = scriptPages.filter((page) => !existWatchlist.includes(page));
    console.info("existWatchlist", existWatchlist);
    console.info("scriptPages", scriptPages);
    console.info("needToBeWatched", needToBeWatched);
    if (needToBeWatched.length === 0) {
        return;
    }
    const userRights = await mw.user.getRights();
    const titlesPerRequest = userRights.includes("apihighlimits") ? 500 : 50;
    console.info("titlesPerRequest", titlesPerRequest);
    for (let i = 0; i * titlesPerRequest < needToBeWatched.length; i++) {
        const start = i * titlesPerRequest;
        const end = (i + 1) * titlesPerRequest;
        const titles = needToBeWatched.slice(start, end);
        console.info("start", start, "end", end, "titles", titles);
        console.info(await api.postWithToken("watch", {
            action: "watch",
            titles: titles.join("|"),
            redirects: true,
        }));
    }
})());