用户:RedDragon/Test2:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第1行: | 第1行: | ||
<table class="infobox" cellspacing="3" style="border-collapse:separate;border-spacing:2px;float:right;"> | <table class="infobox" cellspacing="3" style="border-collapse:separate;border-spacing:2px;float:right;"> | ||
<tbody> | <tbody> | ||
<tr class="infobox-title"><th colspan="2" style="padding:8px;background:#ccc;">曲目</th></tr> | <tr class="infobox-title"> | ||
<tr><td colspan="2" style="text-align:center;"> | <th colspan="2" style="padding:8px;background:#ccc;">曲目</th> | ||
<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" width="200" height="200"> | </tr> | ||
</td></tr> | <tr> | ||
<tr class="infobox-header"><th colspan="2" style="padding:8px;background:#ccf;">限制</th></tr> | <td colspan="2" style="text-align:center;"> | ||
<tr><th scope="row" class="infobox-label" style="width:90px;background:#ddf;">难度</th><td class="infobox-data" id="difficulty-data">a</td></tr> | <img id="song-image" | ||
<tr><th scope="row" class="infobox-label" style="width:90px;background:#ddf;">流速</th><td class="infobox-data" id="speed-data">b</td></tr> | 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" | ||
<tr><th scope="row" class="infobox-label" style="width:90px;background:#ddf;">MOD</th><td class="infobox-data" id="mod-data">c</td></tr> | width="200" height="200"> | ||
<tr><th scope="row" class="infobox-label" style="width:90px;background:#ddf;">其他</th><td class="infobox-data" id="other-data">d</td></tr> | </td> | ||
</tbody></table> | </tr> | ||
<tr class="infobox-header"> | |||
<th colspan="2" style="padding:8px;background:#ccf;">限制</th> | |||
</tr> | |||
<tr> | |||
<th scope="row" class="infobox-label" style="width:90px;background:#ddf;">难度</th> | |||
<td class="infobox-data" id="difficulty-data">a</td> | |||
</tr> | |||
<tr> | |||
<th scope="row" class="infobox-label" style="width:90px;background:#ddf;">流速</th> | |||
<td class="infobox-data" id="speed-data">b</td> | |||
</tr> | |||
<tr> | |||
<th scope="row" class="infobox-label" style="width:90px;background:#ddf;">MOD</th> | |||
<td class="infobox-data" id="mod-data">c</td> | |||
</tr> | |||
<tr> | |||
<th scope="row" class="infobox-label" style="width:90px;background:#ddf;">其他</th> | |||
<td class="infobox-data" id="other-data">d</td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
<script> | <script> | ||
mw.loader.using('mediawiki.api').then(function () { | |||
$(document).ready(function () { | |||
var apiUrl = mw.config.get('wgScriptPath') + '/api.php' | |||
var | |||
$.ajax({ | $.ajax({ | ||
url: | url: apiUrl, | ||
data: { | data: { | ||
action: 'parse', | action: 'parse', | ||
page: | page: '曲目列表', | ||
prop: 'text', | prop: 'text', | ||
format: 'json' | format: 'json' | ||
| 第73行: | 第49行: | ||
var content = data.parse.text['*'] | var content = data.parse.text['*'] | ||
var $content = $('<div>').html(content) | var $content = $('<div>').html(content) | ||
var songs = [] | |||
$content.find('.wikitable tr').each(function (index) { | |||
if (index === 0) return | |||
var $cells = $(this).find('td, th') | |||
if ($cells.length >= 7) { | |||
var song = { | |||
image: extractImageUrl($cells.eq(0)), | |||
title: $cells.eq(1).text().trim(), | |||
ez: $cells.eq(4).text().trim(), | |||
hd: $cells.eq(5).text().trim(), | |||
in: $cells.eq(6).text().trim() | |||
} | |||
if (song.title) songs.push(song) | |||
} | |||
}) | }) | ||
if (songs.length > 0) { | |||
var randomSong = songs[Math.floor(Math.random() * songs.length)] | |||
loadSongDetails(randomSong) | |||
} | |||
}, | }, | ||
error: function () { | error: function (xhr, status, error) { | ||
console.error('获取曲目列表失败:', error) | |||
useMockData() | |||
} | } | ||
}) | }) | ||
function extractImageUrl($cell) { | |||
var $img = $cell.find('img') | |||
if ($img.length > 0) return $img.attr('src') || $img.attr('data-src') | |||
return $cell.text().trim() | |||
} | |||
function loadSongDetails(song) { | |||
updateSongInfo(song) | |||
$.ajax({ | |||
url: mw.config.get('wgScriptPath') + '/api.php', | |||
data: { | |||
action: 'parse', | |||
page: song.title, | |||
prop: 'text', | |||
format: 'json' | |||
}, | |||
success: function (data) { | |||
var content = data.parse.text['*'] | |||
var $content = $('<div>').html(content) | |||
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) { | |||
if ($element.length === 0) return null | |||
var bgColor = $element.css('background-color') | |||
if (bgColor) { | |||
if (bgColor.startsWith('rgb')) { | |||
var 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) { | |||
$('.infobox-title th').text(song.title) | |||
if (song.image) $('#song-image').attr('src', song.image) | |||
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) { | |||
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-color:' + colors[diff] + ';padding:0 0.80em;margin:0.1em 0.50em;">' + diff + ' ' + level + '</span>' | |||
} | |||
function updateStyles(styles) { | |||
$('.infobox-title th').css('background', styles.titleStyle) | |||
$('.infobox-header th').css('background', styles.headerStyle) | |||
$('.infobox-label').css('background', styles.labelStyle) | |||
} | |||
function generateRandomRestrictions() { | |||
var randomDifficulty = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)] | |||
$('#difficulty-data').html(randomDifficulty) | |||
var speedOptions = ["无限制", "无限制", "无限制"].concat(Array.from({ length: 91 }, (_, i) => (i + 10) / 10.0)) | |||
$('#speed-data').text(speedOptions[Math.floor(Math.random() * speedOptions.length)]) | |||
var modOptions = ["无MOD", "MIRROR", "HIDDEN", "FLASH"] | |||
var otherOptions = ["无限制", "仅允许GOOD及以上", "禁止MISS", "连击数≥500"] | |||
$('#mod-data').text(modOptions[Math.floor(Math.random() * modOptions.length)]) | |||
$('#other-data').text(otherOptions[Math.floor(Math.random() * otherOptions.length)]) | |||
} | |||
var | function useMockData() { | ||
var mockSong = { | |||
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", | |||
} | ez: "1", | ||
hd: "6", | |||
in: "11" | |||
} | |||
updateSongInfo(mockSong) | |||
updateStyles({ | |||
titleStyle: '#94E1FF', | |||
headerStyle: '#A3E5FF', | |||
labelStyle: '#B2E9FE' | |||
}) | |||
} | |||
}) | |||
}) | }) | ||
</script> | </script> | ||
神秘的随机挑战! | 神秘的随机挑战! | ||
---- | ---- | ||
2025年10月19日 (日) 07:12的版本
<tbody>
</tbody>
| 曲目 | |
|---|---|
<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"
width="200" height="200">
|
|
| 限制 | |
| 难度 | a |
| 流速 | b |
| MOD | c |
| 其他 | d |
<script>
mw.loader.using('mediawiki.api').then(function () {
$(document).ready(function () {
var apiUrl = mw.config.get('wgScriptPath') + '/api.php'
$.ajax({
url: apiUrl,
data: {
action: 'parse',
page: '曲目列表',
prop: 'text',
format: 'json'
},
success: function (data) {
var content = data.parse.text['*']
var $content = $('
').html(content)
var songs = []
$content.find('.wikitable tr').each(function (index) {
if (index === 0) return
var $cells = $(this).find('td, th')
if ($cells.length >= 7) {
var song = {
image: extractImageUrl($cells.eq(0)),
title: $cells.eq(1).text().trim(),
ez: $cells.eq(4).text().trim(),
hd: $cells.eq(5).text().trim(),
in: $cells.eq(6).text().trim()
}
if (song.title) songs.push(song)
}
})
if (songs.length > 0) {
var randomSong = songs[Math.floor(Math.random() * songs.length)]
loadSongDetails(randomSong)
}
},
error: function (xhr, status, error) {
console.error('获取曲目列表失败:', error)
useMockData()
}
})
function extractImageUrl($cell) {
var $img = $cell.find('img')
if ($img.length > 0) return $img.attr('src') || $img.attr('data-src')
return $cell.text().trim()
}
function loadSongDetails(song) {
updateSongInfo(song)
$.ajax({
url: mw.config.get('wgScriptPath') + '/api.php',
data: {
action: 'parse',
page: song.title,
prop: 'text',
format: 'json'
},
success: function (data) {
var content = data.parse.text['*']
var $content = $('').html(content)
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) {
if ($element.length === 0) return null
var bgColor = $element.css('background-color')
if (bgColor) {
if (bgColor.startsWith('rgb')) {
var 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) {
$('.infobox-title th').text(song.title)
if (song.image) $('#song-image').attr('src', song.image)
window.difficultyArray = [
createDiffSpan("EZ", song.ez),
createDiffSpan("HD", song.hd),
createDiffSpan("IN", song.in),
'无限制'
]
generateRandomRestrictions()
}
function createDiffSpan(diff, level) {
var colors = { EZ: '#57E4C4', HD: '#FDBA61', IN: '#FE8661' }
return '' + diff + ' ' + level + ''
}
function updateStyles(styles) {
$('.infobox-title th').css('background', styles.titleStyle)
$('.infobox-header th').css('background', styles.headerStyle)
$('.infobox-label').css('background', styles.labelStyle)
}
function generateRandomRestrictions() {
var randomDifficulty = window.difficultyArray[Math.floor(Math.random() * window.difficultyArray.length)]
$('#difficulty-data').html(randomDifficulty)
var speedOptions = ["无限制", "无限制", "无限制"].concat(Array.from({ length: 91 }, (_, i) => (i + 10) / 10.0))
$('#speed-data').text(speedOptions[Math.floor(Math.random() * speedOptions.length)])
var modOptions = ["无MOD", "MIRROR", "HIDDEN", "FLASH"]
var otherOptions = ["无限制", "仅允许GOOD及以上", "禁止MISS", "连击数≥500"]
$('#mod-data').text(modOptions[Math.floor(Math.random() * modOptions.length)])
$('#other-data').text(otherOptions[Math.floor(Math.random() * otherOptions.length)])
}
function useMockData() {
var mockSong = {
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",
ez: "1",
hd: "6",
in: "11"
}
updateSongInfo(mockSong)
updateStyles({
titleStyle: '#94E1FF',
headerStyle: '#A3E5FF',
labelStyle: '#B2E9FE'
})
}
})
})
</script> 神秘的随机挑战!
User:RedDragon/Test User:RedDragon/Test1 User:RedDragon/Test2