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 content = content .. tostring(track) if size(song) == 3 then local br = mw.html.create('div') :addClass('mw-collapsible') :attr('id', 'mw-customcollapsible-track' .. i)               :tag('br') :done local desc = mw.html.create('div') :addClass('mw-collapsible') :attr('id', 'mw-customcollapsible-track' .. i)               :tag('div') :css('text-align', 'center') :wikitext("" .. song[3] .. "") :done if chosen ~= i then br                   :addClass('mw-collapsed') :css('display', 'none') desc :addClass('mw-collapsed') :css('display', 'none') end content = content .. tostring(br) .. tostring(desc) end end return content end

return p