Module:Dorumin/Music

local p = {}

local music = mw.loadData('Module:Dorumin/Music/data')

function size(table) local count = 0 for _ in pairs(table) do       count = count + 1 end return count end

function p.tracklist return size(music) end

function p.main(frame) math.randomseed(os.time) local content = '' local tracklist = size(music) local chosen = math.random(tracklist) for i, song in ipairs(music) do       local prev = i - 1 if (prev < 1) then prev = tracklist end local next = i + 1 if (next > tracklist) then next = 1 end local track = mw.html.create('div') :addClass('mw-collapsible') :attr('id', 'mw-customcollapsible-track' .. i)           :tag('span') :addClass('prev') :addClass('mw-customtoggle-track' .. i)               :addClass('mw-customtoggle-track' .. prev) :wikitext('Previous') :done :wikitext(' - ') :tag('span') :addClass('song') :wikitext('.. song[1 .. ' ' .. song[2] .. ']') :done :wikitext(' - ') :tag('span') :addClass('next') :addClass('mw-customtoggle-track' .. i)               :addClass('mw-customtoggle-track' .. next) :wikitext('Next') :done if chosen ~= i then track :addClass('mw-collapsed') :css('display', 'none') end if size(song) == 3 then track :tag('br'):done :wikitext("" .. song[3] .. "") end content = content .. tostring(track) end return content end

return p