打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:SongPlayer:修订间差异

来自Rizline中文维基
卡介菌
卡介菌留言 | 贡献 (测试版本)
 
卡介菌
卡介菌留言 | 贡献 (修复安全标签问题)
第23行: 第23行:
     local jsCover = mw.text.jsonEncode(imagePath)
     local jsCover = mw.text.jsonEncode(imagePath)


     local html = {}
    -- 将 CSS 和 JS 内容存储在变量中
   
     local css_content = [[
    table.insert(html, [[
<style>
     #song-player-fixed .aplayer {
     #song-player-fixed .aplayer {
         background: var(--color-surface-3, #e6e6e6);
         background: var(--color-surface-3, #e6e6e6);
第50行: 第48行:
         background: var(--color-progressive, #4285f4) !important;
         background: var(--color-progressive, #4285f4) !important;
     }
     }
</style>
     ]]
     ]])
 
   
     local js_content = string.format([[
     table.insert(html, '<link rel="stylesheet" href="/aplayer/dist/APlayer.min.css">')
     mw.loader.using("mediawiki.util").then(function() {
    table.insert(html, '<div id="song-player-fixed"></div>')
      const ap = new APlayer({
     table.insert(html, '<script src="/aplayer/dist/APlayer.min.js"></script>')
        container: document.getElementById("song-player-fixed"),
    table.insert(html, '<script>')
        mini: true,
    table.insert(html, 'mw.loader.using("mediawiki.util").then(function() {')
        fixed: true,
    table.insert(html, '  const ap = new APlayer({')
        audio: [{
    table.insert(html, '    container: document.getElementById("song-player-fixed"),')
          name: %s,
    table.insert(html, '    mini: true,')
          artist: %s,
    table.insert(html, '    fixed: true,')
          url: %s,
    table.insert(html, '    audio: [{')
          cover: %s
    table.insert(html, '      name: ' .. jsTitle .. ',')
        }]
    table.insert(html, '      artist: ' .. jsArtist .. ',')
      });
    table.insert(html, '      url: ' .. jsUrl .. ',')
    });
     table.insert(html, '      cover: ' .. jsCover)
     ]], jsTitle, jsArtist, jsUrl, jsCover)
     table.insert(html, '   }]')
 
     table.insert(html, ' });')
     -- 使用 #tag 解析器函数安全地生成标签
     table.insert(html, '});')
    local style_tag = frame:callParserFunction('tag', 'style', css_content)
    table.insert(html, '</script>')
     local script_tag = frame:callParserFunction('tag', 'script', js_content)
 
     -- 组合最终的HTML输出
    local html = {
        style_tag,
        '<link rel="stylesheet" href="/aplayer/dist/APlayer.min.css">',
        '<div id="song-player-fixed"></div>',
        '<script src="/aplayer/dist/APlayer.min.js"></script>',
        script_tag
    }


     return table.concat(html, '\n')
     return table.concat(html, '\n')

2025年11月29日 (六) 18:18的版本

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

local p = {}

function p.player(frame)
    local args = frame:getParent().args
    local title = args.title
    local artist = args.artist
    local imageName = args.image

    if not title or title == '' or not imageName or imageName == '' then
        return ''
    end

    local sanitizedTitle = title
    sanitizedTitle = sanitizedTitle:gsub(' ', '_')
    sanitizedTitle = sanitizedTitle:gsub('[\\/:*?"<>|]', '-')

    local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH')
    local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}')

    local jsTitle = mw.text.jsonEncode(title)
    local jsArtist = mw.text.jsonEncode(artist or 'Unknown Artist')
    local jsUrl = mw.text.jsonEncode('http://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3')
    local jsCover = mw.text.jsonEncode(imagePath)

    -- 将 CSS 和 JS 内容存储在变量中
    local css_content = [[
    #song-player-fixed .aplayer {
        background: var(--color-surface-3, #e6e6e6);
        color: var(--color-base, #000);
        border: 1px solid var(--border-color-base, #a2a9b1);
        box-shadow: 0 0 10px rgba(0,0,0,0.2);
    }
    #song-player-fixed .aplayer .aplayer-body,
    #song-player-fixed .aplayer .aplayer-list ol {
        background: var(--color-surface-1, #fff);
    }
    #song-player-fixed .aplayer .aplayer-info .aplayer-music *,
    #song-player-fixed .aplayer .aplayer-list ol li {
        color: var(--color-base, #000);
    }
    #song-player-fixed .aplayer .aplayer-list ol li.aplayer-list-light {
        background: var(--color-surface-2, #efefef);
    }
    #song-player-fixed .aplayer .aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar .aplayer-played {
        background: var(--color-progressive, #4285f4) !important;
    }
    #song-player-fixed .aplayer .aplayer-info .aplayer-controller .aplayer-volume-bar-wrap .aplayer-volume-bar .aplayer-volume {
        background: var(--color-progressive, #4285f4) !important;
    }
    ]]

    local js_content = string.format([[
    mw.loader.using("mediawiki.util").then(function() {
      const ap = new APlayer({
        container: document.getElementById("song-player-fixed"),
        mini: true,
        fixed: true,
        audio: [{
          name: %s,
          artist: %s,
          url: %s,
          cover: %s
        }]
      });
    });
    ]], jsTitle, jsArtist, jsUrl, jsCover)

    -- 使用 #tag 解析器函数安全地生成标签
    local style_tag = frame:callParserFunction('tag', 'style', css_content)
    local script_tag = frame:callParserFunction('tag', 'script', js_content)

    -- 组合最终的HTML输出
    local html = {
        style_tag,
        '<link rel="stylesheet" href="/aplayer/dist/APlayer.min.css">',
        '<div id="song-player-fixed"></div>',
        '<script src="/aplayer/dist/APlayer.min.js"></script>',
        script_tag
    }

    return table.concat(html, '\n')
end

return p