__NOTOC__
[https://wiki.biligame.com/tools/BwikiTune 原站点] ==简单说明== {{模板|信息|版本|1.0}} {{模板|信息|说明|用来修复BWIKI平台因JQuery加载异常导致处于小屏幕(<768px)时导航栏(.mobile-nav-menu)和目录(.toc)无法打开的情况}} :注:小屏幕下(<768px)显示的导航栏(.mobile-nav-menu)和目录(.toc),使用了原生js克隆原元素,更改了class名(.mobile-nav-menu → .mw-nav-menu / .toc → .mw-toc)和id名(#toc → #mw-toc),防止jq重复绑定事件,非小屏幕下(>768px)仍然为原来的,修改样式时需要注意和原来的不同,使用和目录以及导航栏相关插件的需要注意兼容性。 ==使用说明== *此方法安装后,能'''自动'''同步更新 {|class="wikitable" style="margin-left:40px" !style="text-align:left"|1、在 https://wiki.biligame.com/你管理的BWIKI/Widget:BwikiTune 页面添加内容 |- | |- !style="text-align:left"|2、在 https://wiki.biligame.com/你管理的BWIKI/MediaWiki:Sitenotice 页面引用 |- | {{#widget:BwikiTune}} |} *至此已完成安装,等待缓存刷新即可显示出来
== 作者 == {{模板|作者|141211391}} == 标签 == ==更新日志== * v1.0(2025-02-12):测试版发布

欢迎来到《魔法使的约定》中文WIKI - 当前用户未登录
WIKI建设交流群:578085100;日服游戏交流群:821895698;中文服游戏交流群:790127155

全站通知:

模块:Id2VideoInfo

来自魔法使的约定WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:Id2VideoInfo/doc创建

-- Module:Id2VideoInfo  (r7: cleaned)
local p = {}

p._VERSION = 'Id2VideoInfo/2025-09-21.r7'

-- ===== Args(使用官方 Module:Arguments)=====
local getArgs
do
    local ok, M = pcall(require, 'Module:Arguments')
    if ok and type(M) == 'table' and type(M.getArgs) == 'function' then
        getArgs = M.getArgs
    else
        getArgs = function(frame)
            if type(frame) ~= 'table' then return {} end
            local parent = type(frame.getParent) == 'function' and frame:getParent() or nil
            local fa = frame.args or {}
            local pa = parent and parent.args or {}
            return setmetatable({}, {
                __index = function(_, k)
                    local v = fa[k]
                    if v == nil or v == '' then v = pa[k] end
                    return v
                end
            })
        end
    end
end

-- ===== 数据加载 =====
local function tryLoad(title)
    local ok, tbl = pcall(mw.loadData, title)
    if ok and type(tbl) == 'table' then return tbl end
    ok, tbl = pcall(require, title)
    if ok and type(tbl) == 'table' then return tbl end
    return nil
end
local function loadDataFlex()
    return tryLoad('Module:Id2VideoInfo/data')
        or tryLoad('Module:Id2VideoInfo/Data')
        or {}
end
local DATA = loadDataFlex()

-- ===== 常量 =====
local VIDEO_PREFIX = 'https://www.bilibili.com/video/'
local SPACE_PREFIX = 'https://space.bilibili.com/'

-- ===== 组一条 wikitext 片段(把 label 本身做成视频超链接)=====
local function wtItem(item)
    if type(item) ~= 'table' then return nil end
    local label = item.label or ''
    local bv    = item.bv or ''
    local uid   = item.uid or ''
    local by    = item.by or ''

    local parts = {}

    -- 1) label:如果有 bvid,则把 label 本身做成外链;否则保留纯文本
    if label ~= '' then
        if bv ~= '' then
            table.insert(parts, ('[%s%s %s]'):format(VIDEO_PREFIX, bv, label))
        else
            table.insert(parts, label)
        end
    else
        -- 无 label 时,若有 bvid,用“视频”作为占位文本
        if bv ~= '' then
            table.insert(parts, ('[%s%s 视频]'):format(VIDEO_PREFIX, bv))
        end
    end

    -- 2) 作者:有 uid 就链到空间;没有就纯文本;没有 by 就不拼
    if by ~= '' then
        if #parts > 0 then table.insert(parts, ' by ') end
        if uid ~= '' then
            table.insert(parts, ('[%s %s]'):format(SPACE_PREFIX .. uid, by))
        else
            table.insert(parts, by)
        end
    end

    local s = table.concat(parts)
    return (s ~= '') and s or nil
end

-- ===== 主入口 =====
function p.main(frame)
    local args = getArgs(frame)
    local id    = tostring(args.id or args[1] or ''):match('^%s*(.-)%s*$')
    local as    = tostring(args.as or 'ul')    -- 'ul' | 'wikitext'
    local wrap  = tostring(args.wrap or '') == '1'
    local mark  = tostring(args.mark or '') == '1'

    if id == '' then return '' end

    local rows = DATA[id]
    local out  = {}
    if type(rows) == 'table' then
        for _, it in ipairs(rows) do
            local line = wtItem(it)
            if line and line ~= '' then out[#out+1] = line end
        end
    end
    if #out == 0 then return '' end

    local body
    if as == 'wikitext' then
        local lines = {}
        for i = 1, #out do lines[i] = '* ' .. out[i] end
        body = '\n' .. table.concat(lines, '\n') .. '\n'
    else
        local ul = mw.html.create('ul'):addClass('id2events-list')
        for _, line in ipairs(out) do ul:tag('li'):wikitext(line) end
        body = tostring(ul)
    end

    if wrap then
        body = tostring(
            mw.html.create('div')
                :addClass('id2events-wrap')
                :wikitext(body)
        )
    end
    if mark then
        body = '<!--ID2EVENTS ' .. id .. ' ' .. p._VERSION .. '-->' .. body .. '<!--/ID2EVENTS-->'
    end
    return body
end

-- ===== 探针 =====
function p.probe(frame)
    local t = mw.title.getCurrentTitle()
    return tostring(
        mw.html.create('div')
            :cssText('border:2px solid #06c;padding:4px;margin:4px 0;background:#f5fbff;color:#024')
            :wikitext(('PROBE OK ver=%s | page=%s (ns=%d)')
                :format(p._VERSION, t and t.fullText or '?', t and t.namespace or -1))
    )
end

-- ===== 纯文本 =====
function p.raw(frame)
    local args = getArgs(frame)
    local id = tostring(args.id or args[1] or ''):match('^%s*(.-)%s*$')
    if id == '' then return '' end
    local rows = DATA[id]
    local out  = {}
    if type(rows) == 'table' then
        for _, it in ipairs(rows) do
            local line = wtItem(it)
            if line and line ~= '' then out[#out+1] = line end
        end
    end
    return table.concat(out, '\n')
end

p.id = p.main
return p