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

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

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


<script>
<script>
     mw.loader.using('mediawiki.api').then(function () {
     document.addEventListener('DOMContentLoaded', function () {
         $(document).ready(function () {
         const baseUrl = window.location.origin + window.location.pathname.split('/wiki/')[0]
            var apiUrl = mw.config.get('wgScriptPath') + '/api.php'
        const apiUrl = baseUrl + '/api.php'


            $.ajax({
        fetch(apiUrl + '?action=parse&page=%E6%9B%B2%E7%9B%AE%E5%88%97%E8%A1%A8&prop=text&format=json')
                url: apiUrl,
            .then(response => response.json())
                data: {
            .then(data => {
                    action: 'parse',
                const content = data.parse.text['*']
                    page: '曲目列表',
                const parser = new DOMParser()
                    prop: 'text',
                const doc = parser.parseFromString(content, 'text/html')
                    format: 'json'
                const songs = []
                },
                success: function (data) {
                    var content = data.parse.text['*']
                    var $content = $('<div>').html(content)
                    var songs = []


                    $content.find('.wikitable tr').each(function (index) {
                const rows = doc.querySelectorAll('.wikitable tr')
                        if (index === 0) return
                rows.forEach((row, index) => {
                        var $cells = $(this).find('td, th')
                    if (index === 0) return
                        if ($cells.length >= 7) {
                    const cells = row.querySelectorAll('td, th')
                            var song = {
                    if (cells.length >= 7) {
                                image: extractImageUrl($cells.eq(0)),
                        const song = {
                                title: $cells.eq(1).text().trim(),
                            image: extractImageUrl(cells[0]),
                                ez: $cells.eq(4).text().trim(),
                            title: cells[1].textContent.trim(),
                                hd: $cells.eq(5).text().trim(),
                            ez: cells[4].textContent.trim(),
                                in: $cells.eq(6).text().trim()
                            hd: cells[5].textContent.trim(),
                            }
                            in: cells[6].textContent.trim()
                            if (song.title) songs.push(song)
                         }
                         }
                     })
                        if (song.title) songs.push(song)
                     }
                })


                    if (songs.length > 0) {
                if (songs.length > 0) {
                        var randomSong = songs[Math.floor(Math.random() * songs.length)]
                    const randomSong = songs[Math.floor(Math.random() * songs.length)]
                        loadSongDetails(randomSong)
                    loadSongDetails(randomSong)
                    }
                 } else {
                 },
                error: function (xhr, status, error) {
                    console.error('获取曲目列表失败:', error)
                     useMockData()
                     useMockData()
                 }
                 }
             })
             })
            .catch(error => {
                console.error('获取曲目列表失败:', error)
                useMockData()
            })
    })


            function extractImageUrl($cell) {
    function extractImageUrl(cell) {
                var $img = $cell.find('img')
        const img = cell.querySelector('img')
                if ($img.length > 0) return $img.attr('src') || $img.attr('data-src')
        if (img) return img.src || img.getAttribute('data-src')
                return $cell.text().trim()
        return cell.textContent.trim()
            }
    }
 
    function loadSongDetails(song) {
        updateSongInfo(song)
 
        const baseUrl = window.location.origin + window.location.pathname.split('/wiki/')[0]
        const apiUrl = baseUrl + '/api.php'
 
        fetch(apiUrl + '?action=parse&page=' + encodeURIComponent(song.title) + '&prop=text&format=json')
            .then(response => response.json())
            .then(data => {
                const content = data.parse.text['*']
                const parser = new DOMParser()
                const doc = parser.parseFromString(content, 'text/html')


            function loadSongDetails(song) {
                const titleStyle = getBackgroundColor(doc.querySelector('.infobox-title'))
                 updateSongInfo(song)
                 const headerStyle = getBackgroundColor(doc.querySelector('.infobox-header'))
                const labelStyle = getBackgroundColor(doc.querySelector('.infobox-label'))


                 $.ajax({
                 updateStyles({
                     url: mw.config.get('wgScriptPath') + '/api.php',
                     titleStyle: titleStyle || '#94E1FF',
                    data: {
                    headerStyle: headerStyle || '#A3E5FF',
                        action: 'parse',
                    labelStyle: labelStyle || '#B2E9FE'
                        page: song.title,
                })
                        prop: 'text',
            })
                        format: 'json'
            .catch(() => {
                    },
                updateStyles({
                    success: function (data) {
                    titleStyle: '#94E1FF',
                        var content = data.parse.text['*']
                    headerStyle: '#A3E5FF',
                        var $content = $('<div>').html(content)
                    labelStyle: '#B2E9FE'
                        updateStyles({
                            titleStyle: getBackgroundColor($content.find('.infobox-title')) || '#94E1FF',
                            headerStyle: getBackgroundColor($content.find('.infobox-header')) || '#A3E5FF',
                            labelStyle: getBackgroundColor($content.find('.infobox-label')) || '#B2E9FE'
                        })
                    },
                    error: function () {
                        updateStyles({
                            titleStyle: '#94E1FF',
                            headerStyle: '#A3E5FF',
                            labelStyle: '#B2E9FE'
                        })
                    }
                 })
                 })
             }
             })
    }


            function getBackgroundColor($element) {
    function getBackgroundColor(element) {
                if ($element.length === 0) return null
        if (!element) return null
                var bgColor = $element.css('background-color')
        const bgColor = element.style.backgroundColor
                if (bgColor) {
        if (bgColor) {
                    if (bgColor.startsWith('rgb')) {
            if (bgColor.startsWith('rgb')) {
                        var rgb = bgColor.match(/\d+/g)
                var rgb = bgColor.match(/\d+/g)
                        if (rgb) {
                if (rgb) {
                            if (rgb.length === 3) {
                    if (rgb.length === 3) {
                                return '#' +
                        return '#' +
                                    ('0' + parseInt(rgb[0]).toString(16)).slice(-2) +
                            ('0' + parseInt(rgb[0]).toString(16)).slice(-2) +
                                    ('0' + parseInt(rgb[1]).toString(16)).slice(-2) +
                            ('0' + parseInt(rgb[1]).toString(16)).slice(-2) +
                                    ('0' + parseInt(rgb[2]).toString(16)).slice(-2)
                            ('0' + parseInt(rgb[2]).toString(16)).slice(-2)
                            }
                        }
                     }
                     }
                 }
                 }
                return bgColor
             }
             }
        }
        return bgColor
    }


            function updateSongInfo(song) {
    function updateSongInfo(song) {
                $('.infobox-title th').text(song.title)
        const titleElement = document.querySelector('.infobox-title th')
                if (song.image) $('#song-image').attr('src', song.image)
        titleElement.textContent = song.title


                window.difficultyArray = [
        const imageElement = document.getElementById('song-image')
                    createDiffSpan("EZ", song.ez),
        if (song.image) imageElement.src = song.image
                    createDiffSpan("HD", song.hd),
                    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>'
                ]


                generateRandomRestrictions()
        window.difficultyArray = [
            }
            createDiffSpan("EZ", song.ez),
            createDiffSpan("HD", song.hd),
            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>'
        ]
 
        generateRandomRestrictions()
    }


            function createDiffSpan(diff, level) {
    function createDiffSpan(diff, level) {
                var 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-color:${colors[diff]};padding:0 0.80em;margin:0.1em 0.50em;">${diff} ${level}</span>`
            }
    }


            function updateStyles(styles) {
    function updateStyles(styles) {
                $('.infobox-title th').css('background', styles.titleStyle)
        document.querySelector('.infobox-title th').style.background = styles.titleStyle
                $('.infobox-header th').css('background', styles.headerStyle)
        document.querySelector('.infobox-header th').style.background = styles.headerStyle
                $('.infobox-label').css('background', styles.labelStyle)
        document.querySelectorAll('.infobox-label').forEach(label => {
            }
            label.style.background = styles.labelStyle
        })
    }


            function generateRandomRestrictions() {
    function generateRandomRestrictions() {
                var randomDifficulty = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)]
        const difficultyElement = document.getElementById('difficulty-data')
                $('#difficulty-data').html(randomDifficulty)
        const randomDifficulty = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)]
        difficultyElement.innerHTML = randomDifficulty


                var speedOptions = ["无限制", "无限制", "无限制"].concat(Array.from({ length: 91 }, (_, i) => (i + 10) / 10.0))
        const speedOptions = ["无限制", "无限制", "无限制"]
                $('#speed-data').text(speedOptions[Math.floor(Math.random() * speedOptions.length)])
        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)]


                var modOptions = ["无MOD", "MIRROR", "HIDDEN", "FLASH"]
        const modOptions = ["无MOD"]
                var otherOptions = ["无限制", "仅允许GOOD及以上", "禁止MISS", "连击数≥500"]
        const otherOptions = ["无限制"]
                $('#mod-data').text(modOptions[Math.floor(Math.random() * modOptions.length)])
        document.getElementById('mod-data').textContent = modOptions[Math.floor(Math.random() * modOptions.length)]
                $('#other-data').text(otherOptions[Math.floor(Math.random() * otherOptions.length)])
        document.getElementById('other-data').textContent = otherOptions[Math.floor(Math.random() * otherOptions.length)]
            }
    }


            function useMockData() {
    function useMockData() {
                var mockSong = {
        const mockSong = {
                    title: "Pastel Lines",
            title: "Pastel Lines",
                    image: "/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",
            image: "/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",
                    ez: "1",
            ez: "1",
                    hd: "6",
            hd: "6",
                    in: "11"
            in: "11"
                }
        }
                updateSongInfo(mockSong)
        updateSongInfo(mockSong)
                updateStyles({
        updateStyles({
                    titleStyle: '#94E1FF',
            titleStyle: '#94E1FF',
                    headerStyle: '#A3E5FF',
            headerStyle: '#A3E5FF',
                    labelStyle: '#B2E9FE'
            labelStyle: '#B2E9FE'
                })
            }
         })
         })
     })
     }
</script>
</script>
</html>
</html>

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

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

神秘的随机挑战!


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