打开/关闭搜索
搜索
打开/关闭菜单
5
6
1
403
夜幕之下
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
上传文件
打开/关闭外观设置菜单
通知
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
查看“︁模块:CardData”︁的源代码
来自夜幕之下
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
←
模块:CardData
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
管理员
您可以查看和复制此页面的源代码。
local p = {} local API = "https://data.saltedkiss.org/items/cards" -- 解析JSON local function parseJson(str) local ok, data = pcall(mw.text.jsonDecode, str) if ok then return data end return nil end -- HTTP请求 local function request(url) local res = mw.http.fetch(url) if res.status == 200 then return res.body end return nil end function p.card(frame) local name = frame.args[1] or frame.args.name if not name then return "未提供角色名" end local fields = table.concat({ "stylename", "stories.*", "stories.story.*" }, ",") local url = API .. "?fields=" .. mw.uri.encode(fields) .. "&filter[stylename][_eq]=" .. mw.uri.encode(name) local raw = request(url) if not raw then return "API请求失败" end local json = parseJson(raw) if not json or not json.data or not json.data[1] then return "未获取到数据" end local card = json.data[1] local html = {} table.insert(html, '<div class="card-story">') table.insert(html, '<h2>小传</h2>') if card.stories then for _,storyGroup in ipairs(card.stories) do if storyGroup.story then for _,story in ipairs(storyGroup.story) do if story.text then local text = mw.text.nowiki(story.text) text = text:gsub("\n","<br>") table.insert(html, '<p class="story-text">' .. text .. '</p>' ) end end end end else table.insert(html, "<p>未获取到数据</p>") end table.insert(html, '</div>') return table.concat(html,"\n") end return p
该页面嵌入的页面:
模块:CardData/doc
(
查看源代码
)
返回
模块:CardData
。
查看“︁模块:CardData”︁的源代码
来自夜幕之下