本网站正在建设中(~ ̄▽ ̄)~

  • 你好~!欢迎来到中文歌声合成个人收集站-VCPedia.cn!
  • 若发现页面信息有误投稿至本站,请联系管理员。

Module:交叉颜色

VCPedia.cn ——关于中文歌声合成的一切。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
  1. --协力:User:サンムル
  2. local p = {}
  3. function p._main(args,toggle)
  4. local texts = {}
  5. local colors = {}
  6. for k, v in pairs(args) do
  7. if type(k) == 'string' then --如果是字符串则匹配c开头
  8. local index = k:match "^c(%d+)$"
  9. if index then colors[tonumber(index)] = v end
  10. else --是数字
  11. texts[k] = v
  12. end
  13. end
  14. colors[0] = colors[#colors] -- 余数等于0时输出除数域
  15. --渲染部分
  16. local root = mw.html.create 'span'
  17. for i, v in ipairs(texts) do
  18. root:tag 'span'
  19. :wikitext(v)
  20. :css {color = colors[i%#colors],
  21. ["data-color"] = toggle and color}
  22. :addClass(toggle and 'colorToggleBlock')
  23. end
  24. return root
  25. end
  26. function p.main ( frame )
  27. local wrappers = { ['Template:交叉颜色'] = true, ['Template:交叉颜色护眼版'] = true }
  28. local toggle = frame.args["toggle"]
  29. local parent = frame:getParent()
  30. if parent and wrappers[parent:getTitle()] then
  31. frame = parent
  32. end
  33. local args = frame.args
  34. return p._main(args,toggle)
  35. end
  36. return p