Module:Sandbox/鬼影233
跳到导航
跳到搜索
local p = {}
local pairs = pairs
local site = mw.site
local string = string
local lower = string.lower
local template = site.namespaces.Template.name
local function getFrame(frame)
local parent = frame:getParent()
if parent and parent:getTitle() == 'User:鬼影233/虽然到现在还没有想好名字但总之先在这里随便写个名字' then
return parent
end
return frame
end
function p.power(frame)
frame = getFrame(frame)
local args = frame.args
local by = ({
["cascading style sheets"] = "CSS",
["m+"] = "MSP",
["ms+"] = "MSP",
css = "CSS",
gayhub = "GitHub",
gh = "GitHub",
github = "GitHub",
javascript = "JS",
js = "JS",
json = "JSON",
less = "less",
lua = "Lua",
mediawiki = "MediaWiki",
minerva = "Minerva",
minervaneue = "Minerva",
module = "Lua",
moeskin = "MoeSkin",
moeskinplus = "MSP",
ms = "MoeSkin",
msp = "MSP",
mw = "MediaWiki",
nord = "Nord",
py = "Python",
python = "Python",
sass = "Sass",
scribunto = "Lua",
scss = "Sass",
ts = "TS",
typescript = "TS",
vector = "Vector",
wikitext = "Wikitext",
})[lower(args.by)] or args.by or "???"
local bg = ({
CSS = "639",
GitHub = "25292E",
JS = "F1E05A",
JSON = "292929",
less = "1D365D",
Lua = "000080",
MediaWiki = "F8F9FA",
Minerva = "EAECF0",
MoeLatte = "1AA2AA",
MoeSkin = "25B449",
MSP = "FFF",
Nord = "2E3440",
Python = "3572A5",
Sass = "C6538C",
TS = "3178C6",
Vector = "F6F6F6",
Wikitext = "F6F6F6",
})[by] or "000"
local darkOnLight = ({
JS = true,
MediaWiki = true,
Minerva = true,
MSP = true,
Vector = true,
Wikitext = true,
})[by]
return '<span class="plainlinks" style="float:' ..
(args.float or 'right') ..
';clear:both;">' ..
(args.at and ('[' .. args.at .. ' ') or (args["in"] and ('[[' .. args["in"] .. '|') or '')) ..
'<code style="display:inline-block;width:5.5em;text-align:center;background-color:#' ..
bg ..
';border:1px solid transparent;border-radius:0;padding:.5em 1em;margin:.125em;box-shadow:inset 0 0 0 ' ..
(darkOnLight and 1.25 or 1) ..
'px currentColor,0 0 .125em #' ..
bg .. ';font-weight:' .. (darkOnLight and 800 or 700) .. ';line-height:1;font-size:1rem;color:#' .. (({
CSS = "EBEBEB",
JS = "2E2E2C",
MediaWiki = "000",
Minerva = "222",
MoeLatte = "E6E9EF",
MSP = "25B449",
Nord = "88C0D0",
Python = "FFD343",
Vector = "000",
Wikitext = "000",
})[by] or "FFF") ..
';">' .. by .. '</code>' .. (args.at and ']' or (args["in"] and ']]' or '')) .. '</span>'
end
function p.tryIn(frame)
frame = getFrame(frame)
local args = frame.args
return '<span class="tryIn" data-skin="' .. (args.skin or "moeskin vector") ..
'" data-type="' .. (args.type or "css") .. '" style="display:none;">' ..
(args[1] or "") ..
'</span>'
end
local function cleanupArgs(args, drop)
local t = {}
for k, v in pairs(args) do
if not drop[k] then
t[k] = v
end
end
return t
end
local function argsStringify(args, multiline)
local suffix = multiline and "\n" or ""
local _args = suffix
for k, v in pairs(args) do
if type(k) == "number" then
_args = _args .. "|" .. v .. suffix
else
_args = _args .. "|" .. k .. "=" .. v .. suffix
end
end
return _args
end
function p.import(frame)
frame = getFrame(frame)
local args = frame.args
local tag = args.tag or "code"
local lang = lower(args.lang or "wikitext")
local _in = args["in"] or ""
local at = args.at
local url = at or (site.scriptPath .. '/index.php?title=' .. _in .. '&action=raw&ctype=text/' .. lang)
local multiline = args.multiline == 'true'
local code = ({
css = '@import url("' .. url .. '");',
js = 'mw.loader.load("' .. url .. '");',
lua = 'require("' .. _in .. '")',
})[lang] or
('{{[[' .. (at or (':' .. template .. ':' .. _in .. '|' .. _in)) .. ']]' .. argsStringify(cleanupArgs(args, {
["in"] = not at,
at = true,
tag = true
}), multiline) .. '}}')
return
'<' .. tag .. ' class="prettyprint lang-' .. lang .. '" data-lang="' .. lang ..
(tag == "code" and '" style="word-break:break-all;' or '') .. '">' .. code .. '</' .. tag .. '>'
end
function p.example(frame)
frame = getFrame(frame)
local args = frame.args
local tag = args.tag or "pre"
local _in = args["in"] or ""
local at = args.at
local cleanArgs = cleanupArgs(args, {
["in"] = not at,
at = true,
tag = true
})
local multiline = tag == "pre" and args.multiline ~= 'false' or args.multiline == 'true'
return '代码:<' ..
tag ..
' class="prettyprint lang-wikitext" data-lang="wikitext' ..
(tag == "code" and '" style="word-break:break-all;' or '') .. '">' ..
('{{[[' .. (at or (':' .. template .. ':' .. _in .. '|' .. _in)) .. ']]' .. mw.text.nowiki(argsStringify(cleanArgs, multiline)) .. '}}')
.. '</' .. tag .. '>' .. (tag == "pre" and "" or "<br />") ..
'效果:' .. (tag == "pre" and "<br />" or "") ..
frame:expandTemplate { title = (at or (template .. ':' .. _in)), args = cleanArgs }
end
function p.MSCSSInfo()
return
"<ul><li>(推荐)如果你的[[Special:MyPage/common.css|common.css]]内不存在任何生效的内容(单纯的空白页面或注释不影响),可选择在[[Special:MyPage/moeskin.css|moeskin.css]](的前面)插入引用代码;</li><li>(否则)在[[Special:MyPage/common.css|common.css]](的前面)插入引用代码。</li></ul>"
end
return p