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

模块:SongPlayer:修订间差异

来自Rizline中文维基
 
(未显示同一用户的18个中间版本)
第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
第16行: 第18行:
     end
     end


    -- 处理文件名
     local sanitizedTitle = title:gsub(' ', '_'):gsub('[\\/:*?"<>|]', '-')
     local sanitizedTitle = title:gsub(' ', '_'):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 songUrl = 'https://pan.rizwiki.cn/d/song/' .. encodedTitle .. '.mp3'


     -- 构建 HTML
     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')
     local html = mw.html.create('div')
         :attr('id', 'riz-player')
         :attr('id', 'riz-player')
         :addClass('riz-player-mini')
         :addClass('riz-player-mini')
        :attr('data-url', songUrl)
        :attr('data-image', fullPath)
         :css({
         :css({
             ['--rp-c1'] = c1,
             ['--rp-c1'] = c1,
第31行: 第41行:
             ['--rp-c3'] = c3,
             ['--rp-c3'] = c3,
             ['--rp-c4'] = c4,
             ['--rp-c4'] = c4,
             ['display'] = 'none' -- JS加载前隐藏
             ['display'] = 'none'
         })
         })
      
      
    -- 封面区域
     local cover = html:tag('div'):addClass('rp-cover')
     local cover = html:tag('div'):addClass('rp-cover')
     cover:tag('img'):attr('src', imagePath)
     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>')
     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 info = html:tag('div'):addClass('rp-info')
      
      
     -- 标题和作者
     local topRow = info:tag('div'):addClass('rp-top-row')
     info:tag('div'):addClass('rp-title'):wikitext(title)
   
     info:tag('div'):addClass('rp-artist'):wikitext(artist or 'Unknown')
     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 progressWrap = info:tag('div'):addClass('rp-progress-wrap')
     local progressBar = progressWrap:tag('div'):addClass('rp-progress-bar')
     local progressBar = progressWrap:tag('div'):addClass('rp-progress-bar')
     progressBar:tag('div'):addClass('rp-progress-current') -- 当前进度条
     progressBar:tag('div'):addClass('rp-progress-current')
     progressBar:tag('div'):addClass('rp-progress-handle') -- 拖动滑块
     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>')
     info:tag('div'):addClass('rp-time'):wikitext('<span class="rp-cur">00:00</span> / <span class="rp-dur">00:00</span>')
    -- 隐藏的 audio 标签
    html:tag('audio'):attr('id', 'riz-audio'):attr('src', songUrl):attr('preload', 'metadata')


     return tostring(html)
     return tostring(html)

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