AurLemonCN(讨论 | 贡献) 小无编辑摘要 |
AurLemonCN(讨论 | 贡献) 小无编辑摘要 |
||
第25行: | 第25行: | ||
local stationIndex = 1 | local stationIndex = 1 | ||
local insertedLine = false | |||
while args["Sta" .. stationIndex] do | while args["Sta" .. stationIndex] do | ||
local stationInfo = args["Sta" .. stationIndex] | local stationInfo = args["Sta" .. stationIndex] | ||
local staName | local staName = mw.ustring.match(stationInfo, "([^|]+)") | ||
if staName then | if staName then | ||
第33行: | 第34行: | ||
local stationDiv = li:tag("div"):addClass("name"):wikitext(staName) | local stationDiv = li:tag("div"):addClass("name"):wikitext(staName) | ||
local transferInfo = mw.ustring.match(stationInfo, "|(.+)") | |||
if transferInfo then | if transferInfo then | ||
local transferDiv = stationDiv:tag("div"):addClass("transfer") | local transferDiv = stationDiv:tag("div"):addClass("transfer") | ||
local transferCount = 0 | |||
for transfer in mw.ustring.gmatch(transferInfo, "([^/]+)") do | for transfer in mw.ustring.gmatch(transferInfo, "([^/]+)") do | ||
transferCount = transferCount + 1 | |||
local line, color = mw.ustring.match(transfer, "(.+)%+(%w+)") | local line, color = mw.ustring.match(transfer, "(.+)%+(%w+)") | ||
if line and color then | if line and color then | ||
第42行: | 第46行: | ||
transferLineDiv:tag("div"):css("background-color", color) | transferLineDiv:tag("div"):css("background-color", color) | ||
end | end | ||
end | |||
if transferCount > 0 and not insertedLine then | |||
insertedLine = true | |||
li:done() | |||
stationList:wikitext("<div class='line' style='background-color:" .. lineColor .. ";'></div>") | |||
end | end | ||
end | end |
2023年9月9日 (六) 12:51的版本
local p = {} function p.infobox(frame) local args = frame.args local lineName = args.Name or "" local lineColor = args.Color or "gray" local company = args.Company or "" local firstTrain = args.FirstTrain or "" local lastTrain = args.LastTrain or "" local output = mw.html.create("div") output:addClass("infobox-card") local header = output:tag("div"):addClass("header") header:tag("div"):addClass("line-name"):wikitext(lineName) local detail = header:tag("div"):addClass("detail") detail:tag("div"):addClass("company"):wikitext(company) local time = header:tag("div"):addClass("time") time:tag("div"):addClass("first-train"):wikitext(firstTrain) time:tag("div"):addClass("last-train"):wikitext(lastTrain) local stationList = output:tag("ul"):addClass("station-list") local stationIndex = 1 local insertedLine = false while args["Sta" .. stationIndex] do local stationInfo = args["Sta" .. stationIndex] local staName = mw.ustring.match(stationInfo, "([^|]+)") if staName then local li = stationList:tag("li") local stationDiv = li:tag("div"):addClass("name"):wikitext(staName) local transferInfo = mw.ustring.match(stationInfo, "|(.+)") if transferInfo then local transferDiv = stationDiv:tag("div"):addClass("transfer") local transferCount = 0 for transfer in mw.ustring.gmatch(transferInfo, "([^/]+)") do transferCount = transferCount + 1 local line, color = mw.ustring.match(transfer, "(.+)%+(%w+)") if line and color then local transferLineDiv = transferDiv:tag("div") transferLineDiv:tag("div"):wikitext(line) transferLineDiv:tag("div"):css("background-color", color) end end if transferCount > 0 and not insertedLine then insertedLine = true li:done() stationList:wikitext("<div class='line' style='background-color:" .. lineColor .. ";'></div>") end end end stationIndex = stationIndex + 1 end return tostring(output) end return p