跳转到内容

模組:Progression rainbow

维基百科,自由的百科全书

这是本页的一个历史版本,由風中的刀劍留言 | 贡献2015年5月30日 (六) 15:16编辑。这可能和当前版本存在着巨大的差异。

local list = { 
	{'列表级内容', '#aa88ff'},
	{'小作品级内容', '#ff6666'},
	{'初级内容', '#ffaa66'}, 
	{'丙级内容', '#ffff66'},
	{'乙级内容', '#b2ff66'},
	{'优良级内容', '#66ff66'}, 
	{'甲级内容', '#66ffff'}, 
	{'特色级内容', '#6699ff'},
	{'未评级内容', '#e2e2e2'},
}

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function core( this, total, index )
	local td = mw.html.create( 'td' )
	local lang = mw.getLanguage( 'zh' )
	local percent = tostring( math.floor( this / total * 10000) / 100 ) .. '%'
	
	td
		:css( 'background', list[index][2] )
		:css( 'width', percent )
		:attr( 'title', list[index][1] .. ':' .. this .. '(' .. percent .. ')' )
			
	return tostring( td )
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end
 
function p._main(args)
	args[9] = args[9] or 100
	local temp = ''
	local sum = 0
	
	for i = 1, 8 do
		if not ( args[i] == nil or args[i] == 0 ) then
			temp = temp .. core( args[i], args[9], i )
			sum = sum + args[i]
		end
	end
	
	if sum < tonumber( args[9] ) then
		temp = temp .. core( args[9] - sum, args[9], 9 )
	end
	
	local tr = mw.html.create( 'tr' )
	tr
		:wikitext( temp )
		
	local frame = mw.html.create( 'table' )
	frame
		:css( 'border', '1px solid grey')
		:css( 'height', '10px' )
		:css( 'width', '100%' )
		:attr( 'cellspacing', '1' )
		:wikitext( tostring( tr ) )
		
	return tostring( frame )
end
 
return p