跳至內容

「模組:FUMOCount」:修訂間差異

出自微國家百科
Naritaroad留言 | 貢獻
建立內容為「local p = {} local TARGET_PAGE = "聯合微國家組織會員國列表" local function getContent() return mw.title.new(TARGET_PAGE):getContent() or "" end local function countIndex(content, startPattern, endPattern) local s = endPattern and content:match(startPattern .. "(.-)" .. endPattern) or content:match(startPattern .. "(.*)") if not s then return 0 end local n = 0 for _ in s:gmatch("AutonumTable/index") do n = n…」的新頁面
 
Naritaroad留言 | 貢獻
無編輯摘要
第7行: 第7行:
end
end


local function countIndex(content, startPattern, endPattern)
local function countMatches(s)
    local s = endPattern
        and content:match(startPattern .. "(.-)" .. endPattern)
        or  content:match(startPattern .. "(.*)")
    if not s then return 0 end
     local n = 0
     local n = 0
     for _ in s:gmatch("AutonumTable/index") do n = n + 1 end
     for _ in s:gmatch("AutonumTable/index") do n = n + 1 end
第17行: 第13行:
end
end


-- 成員國數(fumochengyuanguo 區段)
function p.chengyuan(frame)
function p.chengyuan(frame)
     local c = getContent()
     local c = getContent()
     return countIndex(c, "id=fumochengyuanguo", "id=fumoguanchaguo")
     -- 從 fumochengyuanguo 到 fumoguanchaguo 之間
    local section = c:match("id=fumochengyuanguo(.-)id=fumoguanchaguo")
    if not section then return 0 end
    return countMatches(section)
end
end


-- 觀察國數(fumoguanchaguo 區段)
function p.guancha(frame)
function p.guancha(frame)
     local c = getContent()
     local c = getContent()
     return countIndex(c, "id=fumoguanchaguo", nil)
     -- 從 fumoguanchaguo 之後到結尾,用 [%s%S] 跨越換行
    local section = c:match("id=fumoguanchaguo([%s%S]*)")
    if not section then return 0 end
    return countMatches(section)
end
end


-- 會員國總數
function p.total(frame)
function p.total(frame)
     local c = getContent()
     local c = getContent()
     local n = 0
     return countMatches(c)
    for _ in c:gmatch("AutonumTable/index") do n = n + 1 end
    return n
end
end


return p
return p

於 2026年6月10日 (三) 20:01 的修訂

可在模組:FUMOCount/doc建立此模組的說明文件

local p = {}

local TARGET_PAGE = "聯合微國家組織會員國列表"

local function getContent()
    return mw.title.new(TARGET_PAGE):getContent() or ""
end

local function countMatches(s)
    local n = 0
    for _ in s:gmatch("AutonumTable/index") do n = n + 1 end
    return n
end

function p.chengyuan(frame)
    local c = getContent()
    -- 從 fumochengyuanguo 到 fumoguanchaguo 之間
    local section = c:match("id=fumochengyuanguo(.-)id=fumoguanchaguo")
    if not section then return 0 end
    return countMatches(section)
end

function p.guancha(frame)
    local c = getContent()
    -- 從 fumoguanchaguo 之後到結尾,用 [%s%S] 跨越換行
    local section = c:match("id=fumoguanchaguo([%s%S]*)")
    if not section then return 0 end
    return countMatches(section)
end

function p.total(frame)
    local c = getContent()
    return countMatches(c)
end

return p