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') :addClass('track-collapsible') :attr('id', 'mw-customcollapsible-track' .. i)           :tag('div') :addClass('track') :css('display', 'flex') :css('justify-content', 'center') :css('white-space', 'pre') :css('user-select', 'none') :tag('span') :addClass('prev') :addClass('mw-customtoggle-track' .. i)               :addClass('mw-customtoggle-track' .. prev) :css('flex', '1') :css('text-align', 'right') :css('cursor', 'pointer') :wikitext('Previous') :done :tag('span') :addClass('separator') :wikitext(' - ') :done :tag('span') :addClass('song') :wikitext('.. song[1 .. ' ' .. song[2] .. ']') :done :tag('span') :addClass('separator') -- Remove external link icon :css('margin-left', '-12px') :css('background-color', 'white') :wikitext(' - ') :done :tag('span') :addClass('next') :addClass('mw-customtoggle-track' .. i)               :addClass('mw-customtoggle-track' .. next) :css('flex', '1') :css('text-align', 'left') :css('cursor', 'pointer') :wikitext('Next') :done :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