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

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

来自Rizline中文维基
第8行: 第8行:
             <td colspan="2" style="text-align:center;">
             <td colspan="2" style="text-align:center;">
                 <img id="song-image"
                 <img id="song-image"
                     src="/images/thumb/4/41/%E6%8F%92%E7%94%BB%E5%9B%BE%E6%A0%87.png/200px-%E6%8F%92%E7%94%BB%E5%9B%BE%E6%A0%87.png"
                     src="/images/thumb/4/41/%E6%8F%92%E7%94%BB%E5%9B%BE%E6%A0%87.png/300px-%E6%8F%92%E7%94%BB%E5%9B%BE%E6%A0%87.png"
                     width="200" height="200">
                     width="300" height="300">
             </td>
             </td>
         </tr>
         </tr>
第35行: 第35行:


<script>
<script>
     document.addEventListener('DOMContentLoaded', function () {
     document.addEventListener('DOMContentLoaded', () => {
         fetch('https://rizwiki.cn/wiki/%E6%9B%B2%E7%9B%AE%E5%88%97%E8%A1%A8')
         fetch('https://rizwiki.cn/wiki/曲目列表')
             .then(response => {
             .then(r => r.ok ? r.text() : Promise.reject('网络错误'))
                if (!response.ok) {
                    throw new Error('网络响应不正常')
                }
                return response.text()
            })
             .then(html => {
             .then(html => {
                 const parser = new DOMParser()
                 const doc = new DOMParser().parseFromString(html, 'text/html')
                const doc = parser.parseFromString(html, 'text/html')
                 const songs = []
                 const songs = []
                const table = [...doc.querySelectorAll('.wikitable')].find(t =>
                    [...t.querySelectorAll('th')].some(h =>
                        h.textContent.trim().match(/标题|曲目|名称/)
                    )
                )


                 const tables = doc.querySelectorAll('.wikitable')
                 if (table) {
                let targetTable = null
                     [...table.querySelectorAll('tr')].slice(1).forEach(row => {
 
                tables.forEach(table => {
                     const headers = table.querySelectorAll('th')
                    let hasRequiredHeaders = false
                    headers.forEach(header => {
                        const text = header.textContent.trim()
                        if (text.includes('标题') || text.includes('曲目') || text.includes('名称')) {
                            hasRequiredHeaders = true
                        }
                    })
                    if (hasRequiredHeaders) {
                        targetTable = table
                    }
                })
 
                if (targetTable) {
                    const rows = targetTable.querySelectorAll('tr')
                    rows.forEach((row, index) => {
                        if (index === 0) return
                         const cells = row.querySelectorAll('td, th')
                         const cells = row.querySelectorAll('td, th')
                         if (cells.length >= 4) {
                         if (cells.length >= 4) {
                             let titleCell, ezCell, hdCell, inCell
                             const titleCell = cells[cells.length >= 7 ? 1 : 0]
 
                             const song = {
                            if (cells.length >= 7) {
                                title: titleCell.textContent.trim(),
                                titleCell = cells[1]
                                ez: (cells[4] || cells[1]).textContent.trim(),
                                ezCell = cells[4]
                                hd: (cells[5] || cells[2]).textContent.trim(),
                                hdCell = cells[5]
                                in: (cells[6] || cells[3]).textContent.trim()
                                inCell = cells[6]
                            } else if (cells.length >= 4) {
                                titleCell = cells[0]
                                ezCell = cells[1]
                                hdCell = cells[2]
                                inCell = cells[3]
                            }
 
                             if (titleCell) {
                                const song = {
                                    title: titleCell.textContent.trim(),
                                    ez: ezCell ? ezCell.textContent.trim() : '?',
                                    hd: hdCell ? hdCell.textContent.trim() : '?',
                                    in: inCell ? inCell.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)
                                        }
                                    }
                                }
                             }
                             }
                            const img = titleCell.querySelector('img')
                            if (img) song.image = img.src || img.getAttribute('data-src')
                            if (song.title && song.title !== '?' && song.title !== '') songs.push(song)
                         }
                         }
                     })
                     })
                 }
                 }


                 console.log('找到曲目:', songs)
                 songs.length > 0
 
                     ? loadSongColors(songs[Math.floor(Math.random() * songs.length)])
                if (songs.length > 0) {
                     : useMockData()
                     const randomSong = songs[Math.floor(Math.random() * songs.length)]
                     console.log('随机选择:', randomSong)
                    loadSongColors(randomSong)
                } else {
                    useMockData()
                }
             })
             })
             .catch(error => {
             .catch(e => {
                 console.error('获取曲目列表失败:', error)
                 console.error('获取曲目列表失败:', e)
                 useMockData()
                 useMockData()
             })
             })
第127行: 第76行:


     function loadSongColors(song) {
     function loadSongColors(song) {
        console.log('正在获取曲目颜色和图片:', song.title);
         fetch(`https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`)
         fetch(`https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`)
             .then(response => {
             .then(r => r.ok ? r.text() : Promise.reject('页面不存在'))
                if (!response.ok) {
                    throw new Error('曲目页面不存在')
                }
                return response.text()
            })
             .then(html => {
             .then(html => {
                 const parser = new DOMParser()
                 const doc = new DOMParser().parseFromString(html, 'text/html')
                const doc = parser.parseFromString(html, 'text/html')
                 const getStyle = sel => doc.querySelector(sel)?.style.background
 
                 const img = doc.querySelector('.infobox img')
                const titleElem = doc.querySelector('.infobox-title th')
                 let imageUrl = img?.src || img?.getAttribute('data-src')
                 const headerElem = doc.querySelector('.infobox-header th')
                if (imageUrl?.startsWith('/')) imageUrl = 'https://rizwiki.cn' + imageUrl
                const labelElem = doc.querySelector('.infobox-label')
 
                const titleStyle = titleElem ? titleElem.style.background : null
                 const headerStyle = headerElem ? headerElem.style.background : null
                const labelStyle = labelElem ? labelElem.style.background : null
 
                console.log('获取到的颜色:', { titleStyle, headerStyle, labelStyle })
 
                const imgElem = doc.querySelector('.infobox img')
                 let imageUrl = null
                if (imgElem) {
                    imageUrl = imgElem.src || imgElem.getAttribute('data-src')
                    if (imageUrl) {
                        if (imageUrl.startsWith('/')) {
                            imageUrl = 'https://rizwiki.cn' + imageUrl
                        }
                    }
                }


                 updateSongInfo(song, {
                 updateSongInfo(song, {
                     titleStyle: titleStyle || '#94E1FF',
                     titleStyle: getStyle('.infobox-title th') || '#94E1FF',
                     headerStyle: headerStyle || '#A3E5FF',
                     headerStyle: getStyle('.infobox-header th') || '#A3E5FF',
                     labelStyle: labelStyle || '#B2E9FE',
                     labelStyle: getStyle('.infobox-label') || '#B2E9FE',
                     imageUrl: imageUrl,
                     imageUrl: imageUrl,
                     pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`
                     pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`
                 })
                 })
             })
             })
             .catch(error => {
             .catch(e => {
                 console.error('获取曲目颜色失败:', error)
                 console.error('获取曲目颜色失败:', e)
                 updateSongInfo(song, {
                 updateSongInfo(song, {
                     titleStyle: '#94E1FF',
                     titleStyle: '#94E1FF',
第179行: 第103行:
                 })
                 })
             })
             })
    }
    function getComputedColor(element) {
        const tempDiv = document.createElement('div')
        tempDiv.style.cssText = element.style.cssText
        document.body.appendChild(tempDiv)
        const computedStyle = window.getComputedStyle(tempDiv)
        const bgColor = computedStyle.backgroundColor
        document.body.removeChild(tempDiv)
        if (bgColor.startsWith('rgb')) {
            const rgb = bgColor.match(/\d+/g)
            if (rgb) {
                if (rgb.length === 3) {
                    return '#' +
                        ('0' + parseInt(rgb[0]).toString(16)).slice(-2) +
                        ('0' + parseInt(rgb[1]).toString(16)).slice(-2) +
                        ('0' + parseInt(rgb[2]).toString(16)).slice(-2)
                }
            }
        }
        return bgColor
     }
     }


     function updateSongInfo(song, data) {
     function updateSongInfo(song, data) {
         const titleElement = document.querySelector('.infobox-title th')
         document.querySelector('.infobox-title th').textContent = song.title
        titleElement.textContent = song.title
         document.querySelector('.infobox-title th').style.background = data.titleStyle
         titleElement.style.background = data.titleStyle
         document.querySelector('.infobox-header th').style.background = data.headerStyle
 
         document.querySelectorAll('.infobox-label').forEach(label => label.style.background = data.labelStyle)
         const imageContainer = document.querySelector('.infobox td[colspan="2"]')
         let imageElement = document.getElementById('song-image')
 
        if (!imageElement || data.imageUrl) {
            imageContainer.innerHTML = ''
 
            const imageLink = document.createElement('a')
            imageLink.href = data.pageUrl
            imageLink.target = '_blank'


            imageElement = document.createElement('img')
        const container = document.querySelector('.infobox td[colspan="2"]')
            imageElement.id = 'song-image'
        container.innerHTML = `<a href="${data.pageUrl}" target="_blank">
            imageElement.width = 200
        <img id="song-image" width="300" height="300" src="${data.imageUrl || '/images/thumb/4/41/插画图标.png/300px-插画图标.png'}">
            imageElement.height = 200
    </a>`
 
            if (data.imageUrl) {
                console.log('设置图片URL:', data.imageUrl)
                imageElement.src = data.imageUrl
            } else {
                console.log('未找到图片,使用默认图片')
                imageElement.src = '/images/thumb/4/41/%E6%8F%92%E7%94%BB%E5%9B%BE%E6%A0%87.png/200px-%E6%8F%92%E7%94%BB%E5%9B%BE%E6%A0%87.png'
            }
 
            imageLink.appendChild(imageElement)
            imageContainer.appendChild(imageLink)
        }
 
        document.querySelector('.infobox-header th').style.background = data.headerStyle
        const labelElements = document.querySelectorAll('.infobox-label')
        labelElements.forEach(label => {
            label.style.background = data.labelStyle
        })


         window.difficultyArray = [
         window.difficultyArray = [
第245行: 第120行:
             createDiffSpan("HD", song.hd),
             createDiffSpan("HD", song.hd),
             createDiffSpan("IN", song.in),
             createDiffSpan("IN", song.in),
             '<span style="width: max-content;text-align:center;display:inline-block;border-radius:1em;color:white;background-color:#53D6FF;padding:0 0.80em;margin:0.1em 0.50em;">无限制</span>'
             '<span style="width:max-content;text-align:center;display:inline-block;border-radius:1em;color:white;background:#53D6FF;padding:0 0.80em;margin:0.1em 0.50em">无限制</span>'
         ]
         ]


第253行: 第128行:
     function createDiffSpan(diff, level) {
     function createDiffSpan(diff, level) {
         const colors = { EZ: '#57E4C4', HD: '#FDBA61', IN: '#FE8661' }
         const 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-color:${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 difficultyElement = document.getElementById('difficulty-data')
         const speeds = ["无限制", "无限制", "无限制", ...Array.from({ length: 91 }, (_, i) => (i + 10) / 10)]
        const randomDifficulty = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)]
        document.getElementById('difficulty-data').innerHTML = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)]
        difficultyElement.innerHTML = randomDifficulty
         document.getElementById('speed-data').textContent = speeds[Math.floor(Math.random() * speeds.length)]
 
         document.getElementById('mod-data').textContent = ["无MOD"][Math.floor(Math.random() * 1)]
        const speedOptions = ["无限制", "无限制", "无限制"]
         document.getElementById('other-data').textContent = ["无限制"][Math.floor(Math.random() * 1)]
        for (let i = 10; i <= 100; i++) speedOptions.push((i / 10).toFixed(1))
         document.getElementById('speed-data').textContent = speedOptions[Math.floor(Math.random() * speedOptions.length)]
 
        const modOptions = ["无MOD"]
        const otherOptions = ["无限制"]
         document.getElementById('mod-data').textContent = modOptions[Math.floor(Math.random() * modOptions.length)]
         document.getElementById('other-data').textContent = otherOptions[Math.floor(Math.random() * otherOptions.length)]
     }
     }


     function useMockData() {
     function useMockData() {
         console.log('使用模拟数据')
         updateSongInfo({
        const mockSong = {
             title: "Pastel Lines",
             title: "Pastel Lines",
             ez: "1",
             ez: "1",
             hd: "6",
             hd: "6",
             in: "11"
             in: "11"
         }
         }, {
        updateSongInfo(mockSong, {
             titleStyle: '#94E1FF',
             titleStyle: '#94E1FF',
             headerStyle: '#A3E5FF',
             headerStyle: '#A3E5FF',
             labelStyle: '#B2E9FE'
             labelStyle: '#B2E9FE'
         })
         })
    }
    function regenerateChallenge() {
        location.reload()
     }
     }
</script>
</script>

2025年10月19日 (日) 17:50的版本

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

神秘的随机挑战!


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