Модуль:FetchData5: відмінності між версіями

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 187: Рядок 187:
     end
     end
      
      
     -- Генеруємо таблицю з заголовками
     -- Створюємо HTML таблицю за допомогою mw.html
     local table_html = {
     local htmlTable = mw.html.create('table')
         '{| class="wikitable sortable" style="width: 100%; font-size: 14.5px;"',
         :addClass('wikitable sortable')
         '! Турнір !! Роль !! Результат !! Запис',
        :css('width', '100%')
        '|-'
         :css('font-size', '14.5px')
    }
      
      
    -- Додаємо заголовки
    local headerRow = htmlTable:tag('tr')
    headerRow:tag('th'):wikitext('Турнір')
    headerRow:tag('th'):wikitext('Роль')
    headerRow:tag('th'):wikitext('Результат')
    headerRow:tag('th'):wikitext('Запис')
   
    -- Додаємо рядки з іграми
     for _, game in ipairs(games) do
     for _, game in ipairs(games) do
         local result_text = game.result
         local row = htmlTable:tag('tr')
       
        -- Турнір
        row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
            :wikitext(get_tournament_link(game.short, game.tournament))
       
        -- Роль
        row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
            :wikitext(game.role)
       
        -- Результат
        local resultCell = row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
       
         if game.result == "Перемога" then
         if game.result == "Перемога" then
             result_text = "<span style='color:#4caf50; font-weight:normal;'>Перемога</span>"
             resultCell:tag('span')
                :css('color', '#4caf50')
                :css('font-weight', 'normal')
                :wikitext('Перемога')
         elseif game.result == "Поразка" then
         elseif game.result == "Поразка" then
             result_text = "<span style='color:indianred; font-weight:normal;'>Поразка</span>"
             resultCell:tag('span')
                :css('color', 'indianred')
                :css('font-weight', 'normal')
                :wikitext('Поразка')
        else
            resultCell:wikitext(game.result)
         end
         end
          
          
         local link_display = ""
        -- Запис (посилання)
         local linkCell = row:tag('td')
            :css('text-align', 'center')
            :css('padding', '8px')
       
         if game.link and game.link ~= "" then
         if game.link and game.link ~= "" then
             link_display = string.format(
             linkCell:tag('span')
                 '<a href="%s" target="_blank" style="display:inline-block; padding:4px 8px; background-color:white; color:black; border-radius:4px; font-size:13px; text-decoration:none; transition:opacity 0.2s;" onmouseover="this.style.opacity=\'0.7\'" onmouseout="this.style.opacity=\'1\'">Запис</a>',
                 :css('display', 'inline-block')
                game.link
                :css('padding', '4px 8px')
            )
                :css('background-color', 'white')
                :css('color', 'black')
                :css('border-radius', '4px')
                :css('font-size', '13px')
                :wikitext('[' .. game.link .. ' Запис]')
         end
         end
       
        local tournament_link = get_tournament_link(game.short, game.tournament)
       
        table.insert(table_html, string.format(
            '| style="text-align:center; padding: 8px;" | %s || style="text-align:center; padding: 8px;" | %s || style="text-align:center; padding: 8px;" | %s || style="text-align:center; padding: 8px;" | %s',
            tournament_link,
            game.role,
            result_text,
            link_display
        ))
        table.insert(table_html, '|-')
     end
     end
      
      
    table.insert(table_html, '|}')
     return tostring(htmlTable)
   
     return table.concat(table_html, '\n')
end
end