User:SunAfterRain/js/wikirest.js
外观
< User:SunAfterRain | js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
More Information: User:SunAfterRain/js/wikirest
/**
* wikirest.js
* 請參考[[User:SunAfterRain/js/wikirest]]
*
* @author SunAfterRain
* @license BSD 3-Clause for code & CC-BY-SA 4.0 for data.json
*/
// _addText: More Information: [[User:SunAfterRain/js/wikirest]]
// <nowiki>
if (
[2, 3].includes(mw.config.get('wgNamespaceNumber'))
&& mw.config.get('wgRelevantUserName') !== mw.user.getName()
) {
$.when(
$.ready,
mw.loader.using(['ext.wikiLove.defaultOptions', 'ext.gadget.HanAssist']),
fetch(mw.util.getUrl(window.wgWikirestOverrideJsonDataPage ?? 'User:SunAfterRain/js/wikirest.js/data.json', {
action: 'raw',
ctype: 'application/json'
})).then(res => res.json())
).then((_$, require, wikirestData) => {
const HanAssist = require('ext.gadget.HanAssist');
const selectString = HanAssist.conv({
hans: '选择一种餐点:',
hant: '選擇一種餐點:'
});
const noDescr = HanAssist.conv({
hans: '这里还没有描述,等您来撰写。',
hant: '這裡還沒有描述,等您來撰寫。'
});
const keyPrefix = 'zhwiki-wikirest-';
for (const [typeId, type] of wikirestData.entries()) {
if (!type.subtypes.length) {
// 跳過沒有子分類的項目
continue;
}
const typeName = HanAssist.conv(type.name);
const rest = $.wikiLoveOptions.types[`${keyPrefix}${typeId}`] = {
name: typeName,
icon: type.icon ?? '//upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/53px-Wikipedia-logo-v2.svg.png',
select: selectString,
subtypes: {},
text: "{| style=\"background-color: $5; border: 1px solid $6;\"\n|style=\"vertical-align: middle; padding: 5px;\" | [[$3|$4]]\n|style=\"vertical-align: middle; padding: 3px;\" | $1 ~~~~\n|}"
};
for (const [subtypeId, subtype] of type.subtypes.entries()) {
const optionName = HanAssist.conv(subtype.name);
rest.subtypes[`${keyPrefix}${typeId}-${subtypeId}`] = {
fields: ['header', 'message'],
descr: subtype.descr ? HanAssist.conv(subtype.descr) : noDescr,
header: `${optionName}送給您!`,
image: subtype.image,
imageSize: subtype.imageSize || '150px',
option: optionName,
};
}
}
});
}
// </nowiki>