注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
?_=1
来访问最新页面。https://mzh.moegirl.org.cn/User:%E6%9C%BA%E6%99%BA%E7%9A%84%E5%B0%8F%E9%B1%BC%E5%90%9B/gadget/index.js?_=1
!(async function () { // Load utils await mw.loader.using(['mediawiki.api', 'mediawiki.util']) const config = mw.config.get() const { getUrl } = mw.util // Base page (User:<wgUserName>/gadget/) const BASE_PAGE = `User:${config.wgUserName}/gadget/` // Index page (index.json) const INDEX_PAGE = `${BASE_PAGE}index.json` // Get index const GADGETS_LIST = await $.ajax({ url: getUrl(INDEX_PAGE, { action: 'raw', type: 'application/json' }), dataType: 'json', cache: true, }) const getPage = (name) => name.startsWith('/') ? name.slice(1) : `${BASE_PAGE}${name}` function loadScript(name) { const link = getUrl(getPage(name), { action: 'raw', ctype: 'text/javascript', }) return mw.loader.load(link) } function loadStyle(name) { const link = getUrl(getPage(name), { action: 'raw', ctype: 'text/css', }) return mw.loader.load(link, 'text/css') } $.each(GADGETS_LIST, function (_, item) { console.log('Load personal gadget', item) var { name, script, style } = item // Resolve scripts if (script === true && name) { script = name + '.js' } if (typeof script === 'string') script = [script] // Resolve styles if (style === true && name) { style = name + '.css' } if (typeof style === 'string') style = [style] // Fly $.each(script, function (_, name) { loadScript(name) }) $.each(style, function (_, name) { loadStyle(name) }) }) })()