打开/关闭搜索
搜索
打开/关闭菜单
73
0
3
302
CitiZons Wiki
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
上传文件
notifications
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
查看“Module:Infobox Custom”的源代码
来自CitiZons Wiki
查看
阅读
查看源代码
查看历史
associated-pages
页面
讨论
更多操作
←
Module:Infobox Custom
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local p = {} -- 计算亮度:返回 true 表示背景较亮,用黑字;false 表示背景暗,用白字 local function isLightColor(color) local r, g, b -- 处理 rgb(r, g, b) r, g, b = color:match("rgb%((%d+),%s*(%d+),%s*(%d+)%)") if r and g and b then r, g, b = tonumber(r), tonumber(g), tonumber(b) else -- 处理十六进制 #rrggbb local hex = color:match("#(%x%x%x%x%x%x)") if hex then r = tonumber(hex:sub(1, 2), 16) g = tonumber(hex:sub(3, 4), 16) b = tonumber(hex:sub(5, 6), 16) end end if r and g and b then local luminance = 0.299 * r + 0.587 * g + 0.114 * b return luminance > 186 else return true -- 无法判断时默认使用黑字 end end function p.render(frame) local args = frame:getParent().args local output = {} local title = args['标题'] or '未命名条目' local color = args['颜色'] or '#e8e8e8' local useBlackText = isLightColor(color) local fontColor = useBlackText and '#000' or '#fff' table.insert(output, '{| class="infobox" style="width:280px; font-size:90%; text-align:left; background:#f9f9f9; border:1px solid #aaa; border-collapse:collapse;"') table.insert(output, string.format('|-\n! colspan="2" style="text-align:center; font-size:130%%; font-weight:bold; background:%s; color:%s; padding:8px;" | %s', color, fontColor, title)) if args['图片'] and args['图片'] ~= '' then table.insert(output, '|-\n| colspan="2" style="text-align:center;" | [[File:' .. args['图片'] .. '|center|200px]]') end for k, v in pairs(args) do if k ~= '标题' and k ~= '图片' and k ~= '颜色' and v ~= '' then table.insert(output, '|-\n| style="width:40%; font-weight:bold;" | ' .. k .. ' || ' .. v) end end table.insert(output, '|}') return table.concat(output, '\n') end return p
返回
Module:Infobox Custom
。