注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
?_=1
来访问最新页面。https://mzh.moegirl.org.cn/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, })); } })());