跳至內容

模組:FUMOCount

出自微國家百科
於 2026年6月10日 (三) 19:57 由 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…」的新頁面)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)

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

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 + 1 end
    return n
end

-- 成員國數(fumochengyuanguo 區段)
function p.chengyuan(frame)
    local c = getContent()
    return countIndex(c, "id=fumochengyuanguo", "id=fumoguanchaguo")
end

-- 觀察國數(fumoguanchaguo 區段)
function p.guancha(frame)
    local c = getContent()
    return countIndex(c, "id=fumoguanchaguo", nil)
end

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

return p