Немає опису редагування
Немає опису редагування
Рядок 15: Рядок 15:
      
      
     local sections = {}
     local sections = {}
    local games_count = nil
   
    local ok, FetchData = pcall(require, 'Module:FetchData')
    if ok and FetchData and FetchData.games_count_records then
        local mock_frame = {args = {player = page_name}}
        games_count = FetchData.games_count_records(mock_frame)
    end
      
      
     for section_name in mw.ustring.gmatch(content, "\n==%s*([^=]+)%s*==") do
     for section_name in mw.ustring.gmatch(content, "\n==%s*([^=]+)%s*==") do
Рядок 29: Рядок 22:
         clean_name = mw.ustring.gsub(clean_name, "%s*%(%s*%)%s*", "")
         clean_name = mw.ustring.gsub(clean_name, "%s*%(%s*%)%s*", "")
         clean_name = mw.text.trim(clean_name)
         clean_name = mw.text.trim(clean_name)
       
        local display_name = clean_name
        local anchor = clean_name
       
        if mw.ustring.match(clean_name, "Записи ігор") and games_count and games_count ~= "0" then
            display_name = clean_name .. " (" .. games_count .. ")"
            anchor = clean_name .. "_(" .. games_count .. ")"
        end
       
        anchor = mw.ustring.gsub(anchor, " ", "_")
          
          
         if clean_name ~= "" then
         if clean_name ~= "" then
             table.insert(sections, {display = display_name, anchor = anchor})
             table.insert(sections, clean_name)
         end
         end
     end
     end
Рядок 48: Рядок 31:
         return ""
         return ""
     end
     end
   
    local games_count = frame:preprocess("{{#invoke:FetchData|games_count_records|player=" .. page_name .. "}}")
      
      
     local html = '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; overflow:hidden;">'
     local html = '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; overflow:hidden;">'
     html = html .. '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>'
     html = html .. '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>'
      
      
     for i, section in ipairs(sections) do
     for i, name in ipairs(sections) do
        local display_name = name
        local anchor = name
       
        if mw.ustring.match(name, "Записи ігор") and games_count and games_count ~= "0" then
            display_name = name .. " (" .. games_count .. ")"
            anchor = name .. "_(" .. games_count .. ")"
        end
       
        anchor = mw.ustring.gsub(anchor, " ", "_")
       
         local border = ""
         local border = ""
         if i < #sections then
         if i < #sections then
             border = "border-bottom:1px solid rgba(255,255,255,0.05);"
             border = "border-bottom:1px solid rgba(255,255,255,0.05);"
         end
         end
         html = html .. '<div class="l-box-item" style="padding:12px 20px;' .. border .. '">[[#' .. section.anchor .. '|' .. section.display .. ']]</div>'
         html = html .. '<div class="l-box-item" style="padding:12px 20px;' .. border .. '">[[#' .. anchor .. '|' .. display_name .. ']]</div>'
     end
     end
      
      

Версія за 19:26, 8 грудня 2025

Документацію для цього модуля можна створити у Модуль:FetchData7/документація

local p = {}

function p.section_menu(frame)
    local page_name = frame.args.page or mw.title.getCurrentTitle().text
    
    local title = mw.title.new(page_name)
    if not title or not title.exists then
        return ""
    end
    
    local content = title:getContent()
    if not content then
        return ""
    end
    
    local sections = {}
    
    for section_name in mw.ustring.gmatch(content, "\n==%s*([^=]+)%s*==") do
        section_name = mw.text.trim(section_name)
        
        local clean_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
        clean_name = mw.ustring.gsub(clean_name, "%s*%(%s*%)%s*", "")
        clean_name = mw.text.trim(clean_name)
        
        if clean_name ~= "" then
            table.insert(sections, clean_name)
        end
    end
    
    if #sections == 0 then
        return ""
    end
    
    local games_count = frame:preprocess("{{#invoke:FetchData|games_count_records|player=" .. page_name .. "}}")
    
    local html = '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; overflow:hidden;">'
    html = html .. '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>'
    
    for i, name in ipairs(sections) do
        local display_name = name
        local anchor = name
        
        if mw.ustring.match(name, "Записи ігор") and games_count and games_count ~= "0" then
            display_name = name .. " (" .. games_count .. ")"
            anchor = name .. "_(" .. games_count .. ")"
        end
        
        anchor = mw.ustring.gsub(anchor, " ", "_")
        
        local border = ""
        if i < #sections then
            border = "border-bottom:1px solid rgba(255,255,255,0.05);"
        end
        html = html .. '<div class="l-box-item" style="padding:12px 20px;' .. border .. '">[[#' .. anchor .. '|' .. display_name .. ']]</div>'
    end
    
    html = html .. '</div>'
    
    return html
end

return p