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

2134 байти вилучено ,  8 грудня 2025
нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 1: Рядок 1:
local p = {}
local p = {}
-- ================================================
-- КЕШУВАННЯ
-- ================================================


local page_cache = {}
local page_cache = {}
Рядок 22: Рядок 18:
     return content
     return content
end
end
-- ================================================
-- ПІДРАХУНОК ЕЛЕМЕНТІВ
-- ================================================


local function get_section_content(content, section_start)
local function get_section_content(content, section_start)
Рядок 60: Рядок 52:
     return count
     return count
end
end
-- ================================================
-- АВТОМАТИЧНЕ МЕНЮ СЕКЦІЙ
-- ================================================


function p.section_menu(frame)
function p.section_menu(frame)
Рядок 80: Рядок 68:
              
              
             if section_name and section_name ~= "" then
             if section_name and section_name ~= "" then
                 local display_name = section_name
                 local display_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
                 local anchor = section_name
                display_name = mw.ustring.gsub(display_name, "%s*%([^%)]*%)%s*", "")
                display_name = mw.text.trim(display_name)
               
                 local anchor = display_name
                 local section_pos = mw.ustring.find(content, line, 1, true)
                 local section_pos = mw.ustring.find(content, line, 1, true)
                 local count = nil
                 local count = nil
                  
                  
                -- Визначаємо тип секції
                 if section_pos then
                 if mw.ustring.match(section_name, "Нагороди") then
                     local section_content = get_section_content(content, section_pos)
                     -- Прибираємо шаблони з назви
                    display_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
                    display_name = mw.text.trim(display_name)
                    anchor = display_name
                   
                    if section_pos then
                        local section_content = get_section_content(content, section_pos)
                        count = count_table_rows(section_content)
                    end
                   
                elseif mw.ustring.match(section_name, "Сезони") then
                    display_name = "Сезони"
                    anchor = "Сезони"
                      
                      
                     if section_pos then
                     if mw.ustring.match(display_name, "Нагороди") or mw.ustring.match(display_name, "Сезони") then
                        local section_content = get_section_content(content, section_pos)
                         count = count_table_rows(section_content)
                         count = count_table_rows(section_content)
                     end
                     elseif mw.ustring.match(display_name, "Цікаві факти") then
                   
                elseif mw.ustring.match(section_name, "Записи ігор") then
                    -- Тут є шаблон - виконуємо тільки для цієї секції
                    local processed = frame:preprocess(section_name)
                    processed = mw.text.trim(processed)
                    display_name = processed
                    anchor = processed
                   
                elseif mw.ustring.match(section_name, "Цікаві факти") then
                    display_name = "Цікаві факти"
                    anchor = "Цікаві факти"
                   
                    if section_pos then
                        local section_content = get_section_content(content, section_pos)
                         count = count_bullet_points(section_content)
                         count = count_bullet_points(section_content)
                     end
                     end
                   
                else
                    -- Інші секції - просто прибираємо шаблони
                    display_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
                    display_name = mw.text.trim(display_name)
                    anchor = display_name
                 end
                 end
                  
                  
                -- Додаємо кількість якщо є
                 if count and count > 0 then
                 if count and count > 0 then
                     display_name = display_name .. " (" .. count .. ")"
                     display_name = display_name .. " (" .. count .. ")"
                 end
                 end
                  
                  
                -- Формуємо anchor
                 anchor = mw.ustring.gsub(anchor, " ", "_")
                 anchor = mw.ustring.gsub(anchor, " ", "_")
                  
                  
Рядок 151: Рядок 106:
     end
     end
      
      
    -- Будуємо HTML
     local html_parts = {}
     local html_parts = {}
      
      
     table.insert(html_parts, '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; box-sizing:border-box; overflow:hidden;">')
     table.insert(html_parts, '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; box-sizing:border-box; overflow:hidden;">')
   
     table.insert(html_parts, '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>')
     table.insert(html_parts, '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>')