模块:BPersonal/SST:修订间差异

来自Limbo Wiki Mirror
无编辑摘要
无编辑摘要
第20行: 第20行:
     local length = math.floor(string.len(txt) / 18 + 1);-- 6(汉字数)*3(常用汉字的字节数)
     local length = math.floor(string.len(txt) / 18 + 1);-- 6(汉字数)*3(常用汉字的字节数)


     local t = {txt};
     local t = {"<span class=normal>",txt,"</span>"};
     local i = 1
     local i = 2


     while length > 0 do
     while length > 0 do

2024年10月12日 (六) 15:24的版本

此模块的文档可以在模块:BPersonal/SST/doc创建

local frame;

local getArgs = require('Module:Arguments').getArgs;

local p = {}

function makeInvokeFunc(funcName)
    return function(frame)
        local args = getArgs(frame)
        return p[funcName](args)
    end
end

p.f1 = makeInvokeFunc('_RandomTextToNewText')

function p._RandomTextToNewText(args)
    frame = mw.getCurrentFrame();
    local txt = args[1] or "测试文本";
    local newstr = args.newTxt or "永乐至高无上";
    local length = math.floor(string.len(txt) / 18 + 1);-- 6(汉字数)*3(常用汉字的字节数)

    local t = {"<span class=normal>",txt,"</span>"};
    local i = 2

    while length > 0 do
        
        if length < 4 then
            local next = math.random(length);
            if next == length then
                i = i + 1;
                t[i] = "<span class='hide_" .. math.random(9) .. "'>"
                i = i + 1;
                t[i] = string.rep(newstr,next)
                i = i + 1;
                t[i] = "</span>"
            else
                i = i + 1;
                t[i] = "<span class='hide_" .. math.random(9) .. "'>"
                i = i + 1;
                t[i] = string.rep(newstr,next)
                i = i + 1;
                t[i] = "</span>"

                i = i + 1;
                t[i] = "<span class='hide_" .. math.random(9) .. "'>"
                i = i + 1;
                t[i] = string.rep(newstr,length-next)
                i = i + 1;
                t[i] = "</span>"
            end

            length = 0;
        else
            local next = 1 + math.random(3);
            length = length - next;

            i = i + 1;
            t[i] = "<span class='hide_" .. math.random(9) .. "'>"
            i = i + 1;
            t[i] = string.rep(newstr,next)
            i = i + 1;
            t[i] = "</span>"
        end
    end
    return table.concat(t);
end

return p;