Module:Speen
Jump to navigation
Jump to search
local p = {}
function p.main(frame)
local args = frame:getParent() and frame:getParent().args or frame.args
local word = args[1] or "Speen"
local color = "inherit"
local is_fast = false
-- Smart parsing for args 2 and 3 so order doesn't matter
for i = 2, 3 do
local val = args[i]
if val and mw.text.trim(val) ~= "" then
val = mw.text.trim(val)
if string.lower(val) == "fast" then
is_fast = true
else
color = val
end
end
end
-- Auto-append '#' if it's a 3 or 6 character hex string
if color:match("^[0-9a-fA-F]+$") and (#color == 6 or #color == 3) then
color = "#" .. color
end
local root = mw.html.create('span')
root:addClass('speen-wrapper')
-- Apply the speed class and color to the root wrapper
if is_fast then
root:addClass('speen-fast')
end
if color ~= "inherit" then
root:css('color', color)
end
math.randomseed(os.time())
local len = mw.ustring.len(word)
for i = 1, len do
local char = mw.ustring.sub(word, i, i)
if char == " " then
root:wikitext(" ")
else
local letterSpan = root:tag('span')
letterSpan:addClass('speen-letter')
letterSpan:wikitext(char)
local randomDelay = math.random() * 2
letterSpan:css('animation-delay', '-' .. randomDelay .. 's')
end
end
return tostring(root)
end
return p