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

用户:RedDragon/Test2:修订间差异

来自Rizline中文维基
第36行: 第36行:
<script>
<script>
     document.addEventListener('DOMContentLoaded', () => {
     document.addEventListener('DOMContentLoaded', () => {
         fetch('https://rizwiki.cn/wiki/曲目列表')
         fetch('https://rizwiki.cn/api.php?action=query&titles=曲目列表&prop=revisions&rvprop=content&format=json')
             .then(r => r.ok ? r.text() : Promise.reject('网络错误'))
             .then(r => r.ok ? r.json() : Promise.reject('网络错误'))
             .then(html => {
             .then(data => {
                 const doc = new DOMParser().parseFromString(html, 'text/html')
                 const pages = data.query.pages
                const songs = []
                 const pageId = Object.keys(pages)[0]
                const table = [...doc.querySelectorAll('.wikitable')].find(t =>
                const wikitext = pages[pageId].revisions[0]['*']
                    [...t.querySelectorAll('th')].some(h =>
                const songs = parseSongsFromWikitext(wikitext)
                        h.textContent.trim().match(/标题|曲目|名称/)
                    )
                 )
 
                if (table) {
                    [...table.querySelectorAll('tr')].slice(1).forEach(row => {
                        const cells = row.querySelectorAll('td, th')
                        if (cells.length >= 4) {
                            const titleCell = cells[cells.length >= 7 ? 1 : 0]
                            const song = {
                                title: titleCell.textContent.trim(),
                                ez: (cells[4] || cells[1]).textContent.trim(),
                                hd: (cells[5] || cells[2]).textContent.trim(),
                                in: (cells[6] || cells[3]).textContent.trim()
                            }
                            const img = titleCell.querySelector('img')
                            if (img) song.image = img.src || img.getAttribute('data-src')
                            if (song.title) {
                                if (song.title !== '?') {
                                    if (song.title !== '') {
                                        songs.push(song)
                                    }
                                }
                            }
                        }
                    })
                }


                 songs.length > 0
                 songs.length > 0
第80行: 第53行:
             })
             })
     })
     })
    function parseSongsFromWikitext(wikitext) {
        const songs = []
        const rowRegex = /\{\|.*?\|\}(.*?)\|\}/gs
        const lineRegex = /\|\[\[文件:(.*?)\]\]\s*\|\|\s*\[\[(.*?)\]\]\s*\|\|\s*(.*?)\s*\|\|\s*(.*?)\s*\|\|\s*(\d+)\s*\|\|\s*(\d+)\s*\|\|\s*(\d+)/g
        let match
        while ((match = lineRegex.exec(wikitext)) !== null) {
            const song = {
                image: match[1],
                title: match[2],
                author: match[3],
                duration: match[4],
                ez: match[5],
                hd: match[6],
                in: match[7]
            }
            if (song.title) songs.push(song)
        }
        return songs
    }


     function loadSongColors(song) {
     function loadSongColors(song) {
         fetch(`https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`)
         fetch(`https://rizwiki.cn/api.php?action=query&titles=${encodeURIComponent(song.title)}&prop=revisions&rvprop=content&format=json`)
             .then(r => r.ok ? r.text() : Promise.reject('页面不存在'))
             .then(r => r.ok ? r.json() : Promise.reject('页面不存在'))
             .then(html => {
             .then(data => {
                 const doc = new DOMParser().parseFromString(html, 'text/html')
                 const pages = data.query.pages
                 const getStyle = sel => doc.querySelector(sel)?.style.background
                 const pageId = Object.keys(pages)[0]
                 const img = doc.querySelector('.infobox img')
                 const wikitext = pages[pageId].revisions[0]['*']
                 let imageUrl = img?.src || img?.getAttribute('data-src')
                 const styles = parseStylesFromWikitext(wikitext)
                 if (imageUrl?.startsWith('/')) imageUrl = 'https://rizwiki.cn' + imageUrl
                 const imageUrl = parseImageFromWikitext(wikitext)


                 updateSongInfo(song, {
                 updateSongInfo(song, {
                     titleStyle: getStyle('.infobox-title th') || '#94E1FF',
                     titleStyle: styles.title || '#94E1FF',
                     headerStyle: getStyle('.infobox-header th') || '#A3E5FF',
                     headerStyle: styles.header || '#A3E5FF',
                     labelStyle: getStyle('.infobox-label') || '#B2E9FE',
                     labelStyle: styles.label || '#B2E9FE',
                     imageUrl: imageUrl,
                     imageUrl: imageUrl,
                     pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`
                     pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`
第110行: 第104行:
             })
             })
     }
     }
    function parseStylesFromWikitext(wikitext) {
        const styles = {}
        const titleMatch = wikitext.match(/infobox-title.*?background:(#[0-9a-fA-F]+)/)
        if (titleMatch) styles.title = titleMatch[1]
        const headerMatch = wikitext.match(/infobox-header.*?background:(#[0-9a-fA-F]+)/)
        if (headerMatch) styles.header = headerMatch[1]
        const labelMatch = wikitext.match(/infobox-label.*?background:(#[0-9a-fA-F]+)/)
        if (labelMatch) styles.label = labelMatch[1]
        return styles
    }
    function parseImageFromWikitext(wikitext) {
            const fileMatch = wikitext.match(/\[\[文件:(.*?)\]\]/)
            if (fileMatch) {
                const fileName = fileMatch[1]
                return `https://rizwiki.cn/images/thumb/${fileName.substring(0, 1)}/${fileName.substring(0, 2)}/${fileName}/300px-${fileName}`
            }
            return null
        }


     function updateSongInfo(song, data) {
     function updateSongInfo(song, data) {
第203行: 第218行:
</html>
</html>
神秘的随机挑战!
神秘的随机挑战!
{{Infobox
|name        = 随机挑战
|title        = 曲目
|titlestyle  = background:#ccc
|image        = [[File:插画图标.png|200px]]
|imagestyle  =
|headerstyle  = background:#ccf
|labelstyle  = background:#ddf
|header1 = 限制
|label2  = 难度
|data2  = a
|label3  = 流速
|data3  = b
|label4  = MOD
|data4  = c
|label5  = 其他
|data5  = d
}}
----
----
[[User:RedDragon/Test]]
[[User:RedDragon/Test]]
[[User:RedDragon/Test1]]
[[User:RedDragon/Test1]]
[[User:RedDragon/Test2]]
[[User:RedDragon/Test2]]

2025年10月19日 (日) 21:33的版本

曲目
限制
难度 a
流速 b
MOD c
其他 d

神秘的随机挑战!


曲目
限制
难度 a
流速 b
MOD c
其他 d

User:RedDragon/Test User:RedDragon/Test1 User:RedDragon/Test2