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

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

来自Rizline中文维基
第35行: 第35行:


<script>
<script>
     document.addEventListener('DOMContentLoaded', () => {
     document.addEventListener('DOMContentLoaded', function () {
         const encodedUrl = 'https://rizwiki.cn/api.php?action=query%26titles=曲目列表%26prop=revisions%26rvprop=content%26format=json'
         const encodedUrl = 'https://rizwiki.cn/api.php?action=query%26titles=曲目列表%26prop=revisions%26rvprop=content%26format=json'
        const decodedUrl = decodeURIComponent(encodedUrl)


        const decodedUrl = decodeURIComponent(encodedUrl)
         fetch(decodedUrl)
         fetch(decodedUrl)
             .then(r => r.json())
             .then(function (r) { return r.json() })
             .then(data => {
             .then(function (data) {
                console.log('解析后的数据:', data)
 
                 if (data.query) {
                 if (data.query) {
                     if (data.query.pages) {
                     if (data.query.pages) {
第57行: 第55行:
                         }
                         }
                     } else {
                     } else {
                        console.error('数据格式不正确,缺少query.pages')
                         useMockData()
                         useMockData()
                     }
                     }
                 } else {
                 } else {
                    console.error('数据格式不正确,缺少query')
                     useMockData()
                     useMockData()
                 }
                 }
             })
             })
             .catch(e => {
             .catch(function (e) {
                 console.error('获取曲目列表失败:', e)
                 console.error('获取曲目列表失败:', e)
                 useMockData()
                 useMockData()
第73行: 第69行:
     function parseSongsFromWikitext(wikitext) {
     function parseSongsFromWikitext(wikitext) {
         const songs = []
         const songs = []
        console.log('wikitext内容:', wikitext)
        // 分割整个文本,按"|-"来分割每一行
         const rows = wikitext.split('|-')
         const rows = wikitext.split('|-')
        console.log('分割出的行数:', rows.length)


         for (let i = 1; i < rows.length; i++) { // 从1开始跳过表头
         for (let i = 1; i < rows.length; i++) {
             const row = rows[i]
             const row = rows[i]
            console.log(`处理第 ${i} 行:`, row)
             const columns = row.split('\n').filter(function (col) { return col.trim().startsWith('|') })
 
            // 按换行符分割每一列
             const columns = row.split('\n').filter(col => col.trim().startsWith('|'))
            console.log(`第 ${i} 行列数:`, columns.length)


             if (columns.length >= 7) {
             if (columns.length >= 7) {
                // 提取各列数据
                 const imageMatch = columns[0].match(/\[\[文件:([^|\]]+)/)
                 const imageMatch = columns[0].match(/\[\[文件:([^|\]]+)/)
                 const titleMatch = columns[1].match(/\[\[([^|\]]+)/)
                 const titleMatch = columns[1].match(/\[\[([^|\]]+)/)
第102行: 第89行:
                             hd: columns[5].replace(/^\|/, '').trim(),
                             hd: columns[5].replace(/^\|/, '').trim(),
                             in: columns[6].replace(/^\|/, '').trim()
                             in: columns[6].replace(/^\|/, '').trim()
                         };
                         }
 
                        console.log('解析出的曲目:', song)


                         if (song.title) {
                         if (song.title) {
第117行: 第102行:
             }
             }
         }
         }
        console.log('解析出的所有曲目:', songs)
        console.log('总共匹配到:', songs.length, '个曲目')


         return songs
         return songs
第129行: 第111行:


         fetch(decodedUrl)
         fetch(decodedUrl)
             .then(r => r.json())
             .then(function (r) { return r.json() })
             .then(data => {
             .then(function (data) {
                 try {
                 const pages = data.query.pages
                    const pages = data.query.pages
                const pageId = Object.keys(pages)[0]
                    const pageId = Object.keys(pages)[0]
                const pageData = pages[pageId]
                    const pageData = pages[pageId]


                    if (!pageData.revisions) {
                if (!pageData.revisions) {
                        throw new Error('页面不存在')
                    throw new Error('页面不存在')
                    }
                }


                    const wikitext = pageData.revisions[0]['*']
                const wikitext = pageData.revisions[0]['*']
                    const styles = parseStylesFromWikitext(wikitext)
                const styles = parseStylesFromWikitext(wikitext)


                    let imageUrl = null
                let imageUrl = null
                    if (pageData.thumbnail) {
                if (pageData.thumbnail) {
                        if (pageData.thumbnail.source) {
                    if (pageData.thumbnail.source) {
                            imageUrl = pageData.thumbnail.source;
                        imageUrl = pageData.thumbnail.source
                            console.log('获取到的缩略图URL:', imageUrl);
                        }
                     }
                     }
                }


                    updateSongInfo(song, {
                updateSongInfo(song, {
                        titleStyle: styles.title || '#94E1FF',
                    titleStyle: styles.title || '#94E1FF',
                        headerStyle: styles.header || '#A3E5FF',
                    headerStyle: styles.header || '#A3E5FF',
                        labelStyle: styles.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)}`
                    })
                 })
                 } catch (e) {
                    console.error('解析曲目数据失败:', e)
                    throw e
                }
             })
             })
             .catch(e => {
             .catch(function (e) {
                 console.error('获取曲目颜色失败:', e)
                 console.error('获取曲目颜色失败:', e)
                 updateSongInfo(song, {
                 updateSongInfo(song, {
第173行: 第149行:
                 })
                 })
             })
             })
    }
    function parseImageFromWikitext(wikitext) {
        const fileMatch = wikitext.match(/\[\[文件:([^|\]]+)(?:\|[^]]*)?\]\]/)
        if (fileMatch) {
            const fileName = encodeURIComponent(fileMatch[1].trim())
            return `https://rizwiki.cn/wiki/文件:${fileName}`
        }
        return null
     }
     }


     function parseStylesFromWikitext(wikitext) {
     function parseStylesFromWikitext(wikitext) {
         const styles = {}
         const styles = {}
         const titleMatch = wikitext.match(/infobox-title.*?background:(#[0-9a-fA-F]+)/)
         const color1Match = wikitext.match(/\|color1\s*=\s*([^\n}]+)/)
         if (titleMatch) styles.title = titleMatch[1]
         const color3Match = wikitext.match(/\|color3\s*=\s*([^\n}]+)/)
 
         const color4Match = wikitext.match(/\|color4\s*=\s*([^\n}]+)/)
         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 (color1Match) styles.title = color1Match[1].trim()
         if (labelMatch) styles.label = labelMatch[1]
        if (color3Match) styles.header = color3Match[1].trim()
         if (color4Match) styles.label = color4Match[1].trim()


         return styles
         return styles
    }
    function parseImageFromWikitext(wikitext) {
        console.log('曲目页面wikitext:', wikitext)
        // 尝试多种匹配模式
        const patterns = [
            /\[\[文件:([^|\]\n]+)(?:\|[^]\n]*)?\]\]/,  // [[文件:xxx.png]]
            /\[\[File:([^|\]\n]+)(?:\|[^]\n]*)?\]\]/,  // [[File:xxx.png]]
            /src="([^"]+\.(?:png|jpg|jpeg|gif))"/i,    // src="xxx.png"
            /src='([^']+\.(?:png|jpg|jpeg|gif))'/i    // src='xxx.png'
        ]
        for (const pattern of patterns) {
            const match = wikitext.match(pattern)
            if (match) {
                console.log('匹配到的图片:', match[1])
                let fileName = match[1].trim()
                // 如果是文件名,构造图片URL
                if (fileName.includes('.')) {
                    fileName = encodeURIComponent(fileName)
                    return `https://rizwiki.cn/images/thumb/?file=${fileName}&width=300`
                }
                return match[1]
            }
        }
        return null
     }
     }


第231行: 第168行:
         document.querySelector('.infobox-title th').style.background = data.titleStyle
         document.querySelector('.infobox-title th').style.background = data.titleStyle
         document.querySelector('.infobox-header th').style.background = data.headerStyle
         document.querySelector('.infobox-header th').style.background = data.headerStyle
        document.querySelectorAll('.infobox-label').forEach(label => label.style.background = data.labelStyle)


         const container = document.querySelector('.infobox td[colspan="2"]')
         var labelElements = document.querySelectorAll('.infobox-label')
         container.innerHTML = `<a href="${data.pageUrl}" target="_blank">
        for (var i = 0; i < labelElements.length; i++) {
        <img id="song-image" width="300" height="300" src="${data.imageUrl || '/images/thumb/4/41/插画图标.png/300px-插画图标.png'}">
            labelElements[i].style.background = data.labelStyle
    </a>`
        }
 
        var container = document.querySelector('.infobox td[colspan="2"]')
         container.innerHTML = '<a href="' + data.pageUrl + '" target="_blank"><img id="song-image" width="300" height="300" src="' + (data.imageUrl || '/images/thumb/4/41/插画图标.png/300px-插画图标.png') + '"></a>'


         window.difficultyArray = [
         window.difficultyArray = [
第249行: 第188行:


     function createDiffSpan(diff, level) {
     function createDiffSpan(diff, level) {
         const colors = { EZ: '#57E4C4', HD: '#FDBA61', IN: '#FE8661' }
         var colors = { EZ: '#57E4C4', HD: '#FDBA61', IN: '#FE8661' }
         return `<span style="width:max-content;text-align:center;display:inline-block;border-radius:1em;color:white;background:${colors[diff]};padding:0 0.80em;margin:0.1em 0.50em">${diff} ${level}</span>`
         return '<span style="width:max-content;text-align:center;display:inline-block;border-radius:1em;color:white;background:' + colors[diff] + ';padding:0 0.80em;margin:0.1em 0.50em">' + diff + ' ' + level + '</span>'
     }
     }


     function generateRandomRestrictions() {
     function generateRandomRestrictions() {
         const speeds = [...Array(40).fill("无限制"), ...Array.from({ length: 91 }, (_, i) => (i + 10) / 10)]
         var speeds = Array(40).fill("无限制").concat(Array.from({ length: 91 }, function (_, i) { return (i + 10) / 10 }))
         const mods = ["无MOD", "镜像模式", "保护模式", "Bad保护模式", "特殊计量条", "隐藏计量条"]
         var mods = ["无MOD", "无MOD", "无MOD", "镜像模式", "保护模式", "Bad保护模式", "特殊计量条", "隐藏计量条"]
         const others = ["无限制", "静音", "单手", "手持"]
         var others = ["无限制", "静音", "单手", "手持"]


         document.getElementById('difficulty-data').innerHTML = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)]
         document.getElementById('difficulty-data').innerHTML = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)]
         document.getElementById('speed-data').textContent = speeds[Math.floor(Math.random() * speeds.length)]
         document.getElementById('speed-data').textContent = speeds[Math.floor(Math.random() * speeds.length)]


         let selectedMods = []
         var selectedMods = []
         if (Math.random() < 0.3) {
         if (Math.random() < 0.3) { // 只随机一个mod条件的概率
             selectedMods = [mods[Math.floor(Math.random() * mods.length)]]
             selectedMods = [mods[Math.floor(Math.random() * mods.length)]]
         } else {
         } else {
             const count = Math.floor(Math.random() * 3) + 2
             var availableMods = mods.filter(function (m) { return m !== "无MOD" })
            const availableMods = mods.filter(m => m !== "无MOD")
             var shuffled = availableMods.slice().sort(function () { return Math.random() - 0.5 })
             const shuffled = [...availableMods].sort(() => Math.random() - 0.5)
            var count = Math.floor(Math.random() * 3) + 2
             selectedMods = shuffled.slice(0, Math.min(count, availableMods.length))
             selectedMods = shuffled.slice(0, Math.min(count, availableMods.length))


             const hasSpecial = selectedMods.includes("特殊计量条")
             var hasSpecial = selectedMods.includes("特殊计量条")
             if (hasSpecial) {
             if (hasSpecial) {
                 const specialRates = ["特殊计量条100%", "特殊计量条110%", "特殊计量条120%"]
                 var specialRates = ["特殊计量条100%", "特殊计量条110%", "特殊计量条120%"]
                 selectedMods = selectedMods.filter(m => m !== "特殊计量条")
                 selectedMods = selectedMods.filter(function (m) { return m !== "特殊计量条" })
                 selectedMods.push(specialRates[Math.floor(Math.random() * specialRates.length)])
                 selectedMods.push(specialRates[Math.floor(Math.random() * specialRates.length)])
             }
             }
         }
         }


         const modElement = document.getElementById('mod-data')
         var modElement = document.getElementById('mod-data')
         if (selectedMods.length === 1) {
         if (selectedMods.length === 1) {
             modElement.textContent = selectedMods[0]
             modElement.textContent = selectedMods[0]
         } else {
         } else {
             modElement.innerHTML = `<p>${selectedMods.join('<br>')}</p>`
             modElement.innerHTML = '<p>' + selectedMods.join('<br>') + '</p>'
         }
         }


         let selectedOthers = []
         var selectedOthers = []
         if (Math.random() < 0.8) {
         if (Math.random() < 0.8) { // 只随机一个其他条件的概率
             selectedOthers = [others[Math.floor(Math.random() * others.length)]]
             selectedOthers = [others[Math.floor(Math.random() * others.length)]]
         } else {
         } else {
             const count = Math.floor(Math.random() * 2) + 2
             var availableOthers = others.filter(function (o) { return o !== "无限制" })
            const availableOthers = others.filter(o => o !== "无限制")
             var shuffledOthers = availableOthers.slice().sort(function () { return Math.random() - 0.5 })
             const shuffled = [...availableOthers].sort(() => Math.random() - 0.5)
            var otherCount = Math.floor(Math.random() * 2) + 2
             selectedOthers = shuffled.slice(0, Math.min(count, availableOthers.length))
             selectedOthers = shuffledOthers.slice(0, Math.min(otherCount, availableOthers.length))
         }
         }


         const otherElement = document.getElementById('other-data')
         var otherElement = document.getElementById('other-data')
         if (selectedOthers.length === 1) {
         if (selectedOthers.length === 1) {
             otherElement.textContent = selectedOthers[0]
             otherElement.textContent = selectedOthers[0]
         } else {
         } else {
             otherElement.innerHTML = `<p>${selectedOthers.join('<br>')}</p>`
             otherElement.innerHTML = '<p>' + selectedOthers.join('<br>') + '</p>'
         }
         }
     }
     }

2025年10月20日 (一) 00:38的版本

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

神秘的随机挑战!


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

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