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

模块:SongPlayer:修订间差异

来自Rizline中文维基
卡介菌
卡介菌留言 | 贡献 (测试版本)
 
 
(未显示同一用户的26个中间版本)
第1行: 第1行:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


function p.player(frame)
function p.player(frame)
     local args = frame:getParent().args
     local args = getArgs(frame)
   
     local title = args.title
     local title = args.title
     local artist = args.artist
     local artist = args.artist
     local imageName = args.image
     local imageName = args.image
   
    local c1 = args.color1 or '#94E1FF'
    local c2 = args.color2 or '#A3E5FF'
    local c3 = args.color3 or '#B2E9FE'
    local c4 = args.color4 or '#D5F3FE'


     if not title or title == '' or not imageName or imageName == '' then
     if not title or title == '' or not imageName or imageName == '' then
第11行: 第18行:
     end
     end


     local sanitizedTitle = title
     local sanitizedTitle = title:gsub(' ', '_'):gsub('[\\/:*?"<>|]', '-')
    sanitizedTitle = sanitizedTitle:gsub(' ', '_')
    sanitizedTitle = sanitizedTitle:gsub('[\\/:*?"<>|]', '-')
 
     local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH')
     local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH')
     local imagePath = frame:preprocess('{{filepath:' .. imageName .. '}}')
     local songUrl = 'https://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3'


     local jsTitle = mw.text.jsonEncode(title)
     local rawPath = mw.text.trim(frame:preprocess('{{filepath:' .. imageName .. '}}'))
     local jsArtist = mw.text.jsonEncode(artist or 'Unknown Artist')
     local fullPath = rawPath
    local jsUrl = mw.text.jsonEncode('http://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3')
    if fullPath:match('^//') then
     local jsCover = mw.text.jsonEncode(imagePath)
        fullPath = 'https:' .. fullPath
    elseif fullPath:match('^/') and not fullPath:match('^//') then
        fullPath = 'https://rizwiki.cn' .. fullPath
    end
     fullPath = fullPath:gsub(' ', '_')


     local html = {}
     local html = mw.html.create('div')
        :attr('id', 'riz-player')
        :addClass('riz-player-mini')
        :attr('data-url', songUrl)
        :attr('data-image', fullPath)
        :css({
            ['--rp-c1'] = c1,
            ['--rp-c2'] = c2,
            ['--rp-c3'] = c3,
            ['--rp-c4'] = c4,
            ['display'] = 'none'
        })
      
      
     table.insert(html, [[
     local cover = html:tag('div'):addClass('rp-cover')
<style>
    cover:wikitext('[[File:' .. imageName .. '|link=|alt=cover|class=rp-cover-img|300px]]')
    #song-player-fixed .aplayer {
     cover:tag('div'):addClass('rp-btn-toggle'):wikitext('<div class="rp-icon-play"></div><div class="rp-icon-pause"></div>')
        background: var(--color-surface-3, #e6e6e6);
 
        color: var(--color-base, #000);
     local info = html:tag('div'):addClass('rp-info')
        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;
    }
</style>
    ]])
      
      
     table.insert(html, '<link rel="stylesheet" href="/aplayer/dist/APlayer.min.css">')
     local topRow = info:tag('div'):addClass('rp-top-row')
     table.insert(html, '<div id="song-player-fixed"></div>')
      
     table.insert(html, '<script src="/aplayer/dist/APlayer.min.js"></script>')
    local textInfo = topRow:tag('div'):addClass('rp-text-info')
    table.insert(html, '<script>')
     textInfo:tag('div'):addClass('rp-title'):wikitext(title)
     table.insert(html, 'mw.loader.using("mediawiki.util").then(function() {')
     textInfo:tag('div'):addClass('rp-artist'):wikitext(artist or '')
    table.insert(html, ' const ap = new APlayer({')
 
     table.insert(html, '   container: document.getElementById("song-player-fixed"),')
     local sideCtrl = topRow:tag('div'):addClass('rp-side-ctrl')
     table.insert(html, '   mini: true,')
     sideCtrl:tag('div'):addClass('rp-side-play')
     table.insert(html, '   fixed: true,')
     sideCtrl:tag('div'):addClass('rp-side-pause')
    table.insert(html, '   audio: [{')
 
     table.insert(html, '     name: ' .. jsTitle .. ',')
     local progressWrap = info:tag('div'):addClass('rp-progress-wrap')
     table.insert(html, '     artist: ' .. jsArtist .. ',')
     local progressBar = progressWrap:tag('div'):addClass('rp-progress-bar')
     table.insert(html, '     url: ' .. jsUrl .. ',')
     progressBar:tag('div'):addClass('rp-progress-current')
     table.insert(html, '     cover: ' .. jsCover)
     progressBar:tag('div'):addClass('rp-progress-handle')
    table.insert(html, '   }]')
 
     table.insert(html, ' });')
     info:tag('div'):addClass('rp-time'):wikitext('<span class="rp-cur">00:00</span> / <span class="rp-dur">00:00</span>')
    table.insert(html, '});')
    table.insert(html, '</script>')


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


return p
return p

2025年12月1日 (一) 16:19的最新版本

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

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.player(frame)
    local args = getArgs(frame)
    
    local title = args.title
    local artist = args.artist
    local imageName = args.image
    
    local c1 = args.color1 or '#94E1FF'
    local c2 = args.color2 or '#A3E5FF'
    local c3 = args.color3 or '#B2E9FE'
    local c4 = args.color4 or '#D5F3FE'

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

    local sanitizedTitle = title:gsub(' ', '_'):gsub('[\\/:*?"<>|]', '-')
    local encodedTitle = mw.uri.encode(sanitizedTitle, 'PATH')
    local songUrl = 'https://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3'

    local rawPath = mw.text.trim(frame:preprocess('{{filepath:' .. imageName .. '}}'))
    local fullPath = rawPath
    if fullPath:match('^//') then
        fullPath = 'https:' .. fullPath
    elseif fullPath:match('^/') and not fullPath:match('^//') then
        fullPath = 'https://rizwiki.cn' .. fullPath
    end
    fullPath = fullPath:gsub(' ', '_')

    local html = mw.html.create('div')
        :attr('id', 'riz-player')
        :addClass('riz-player-mini')
        :attr('data-url', songUrl)
        :attr('data-image', fullPath)
        :css({
            ['--rp-c1'] = c1,
            ['--rp-c2'] = c2,
            ['--rp-c3'] = c3,
            ['--rp-c4'] = c4,
            ['display'] = 'none'
        })
    
    local cover = html:tag('div'):addClass('rp-cover')
    cover:wikitext('[[File:' .. imageName .. '|link=|alt=cover|class=rp-cover-img|300px]]')
    cover:tag('div'):addClass('rp-btn-toggle'):wikitext('<div class="rp-icon-play"></div><div class="rp-icon-pause"></div>')

    local info = html:tag('div'):addClass('rp-info')
    
    local topRow = info:tag('div'):addClass('rp-top-row')
    
    local textInfo = topRow:tag('div'):addClass('rp-text-info')
    textInfo:tag('div'):addClass('rp-title'):wikitext(title)
    textInfo:tag('div'):addClass('rp-artist'):wikitext(artist or '')

    local sideCtrl = topRow:tag('div'):addClass('rp-side-ctrl')
    sideCtrl:tag('div'):addClass('rp-side-play')
    sideCtrl:tag('div'):addClass('rp-side-pause')

    local progressWrap = info:tag('div'):addClass('rp-progress-wrap')
    local progressBar = progressWrap:tag('div'):addClass('rp-progress-bar')
    progressBar:tag('div'):addClass('rp-progress-current')
    progressBar:tag('div'):addClass('rp-progress-handle')

    info:tag('div'):addClass('rp-time'):wikitext('<span class="rp-cur">00:00</span> / <span class="rp-dur">00:00</span>')

    return tostring(html)
end

return p