本WIKI由Legend frog(留言)于2023年10月8日申请开通,除首页外编辑权限开放。祝贺《偶像大师 灰姑娘女孩》企划面世13周年!欢迎各位灰姑娘制作人加入交流群:327967793;如有急切的审核需要则请在加群信息附带“-审核”等字样

全站通知:

模块:Lyrics/hover

来自偶像大师灰姑娘女孩WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

歌词hover模块,对应的模板是{{LyricsKai/hover}}。



local module = {}
 
local getArgs = require('Module:Arguments').getArgs
local buildLyrics = require('Module:Lyrics')._lyrics
local initHandler = require('Module:HooksHandler').init
 
local preSplit = function (original, translated, customArgs)
	-- 旧的示例里面翻译部分也有加,但是实际上没有必要
	return original, mw.ustring.gsub(mw.ustring.gsub(translated, '#HoverWithNextLine', ''), '#NoHover', '')
end
 
local preParse = function (original, translated, customArgs)
	customArgs.noHover = {}
	customArgs.hoverWithNextLine = {}
	for idx, val in ipairs(original) do
		val = mw.ustring.gsub(val, '#NoHover', function()
			customArgs.noHover[idx] = true
			return ''
		end)
		original[idx] = mw.ustring.gsub(val, '#HoverWithNextLine', function()
			customArgs.hoverWithNextLine[idx] = true
			return ''
		end)
	end
end
 
local postParse = function (lines, customArgs)
	local index, all, add, start = 1, #lines, 0, nil
	local warp = function (_start)
		if not _start then _start = start end
		table.insert(lines, _start, '<div class="bg_hover">')
		table.insert(lines, index + 2, '</div>')
		index = index + 2
		add = add + 2
		start = nil
	end
	repeat
		if not customArgs.noHover[index - add] then
			if not customArgs.hoverWithNextLine[index - add] then
				warp(start or index)
			else
				start = start or index
			end
		elseif start then
			warp()
		end
		index = index + 1
	until index > all + add
	if start then warp() end
end
 
function module.initHooks(args, hooksHandler, customArgs)
	return hooksHandler({ preSplit = preSplit, preParse = preParse, postParse = postParse })
end
 
function module.main(frame)
	local args = getArgs(frame, {wrappers='Template:LyricsKai/colors/hover/Sandbox'})
	local hooksHandler, customArgs = initHandler(), {}
	local hookTrigger = module.initHooks(args, hooksHandler, customArgs)
 
	return buildLyrics(args, hookTrigger, customArgs)
end
 
return module