用户: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) | |||
fetch(decodedUrl) | fetch(decodedUrl) | ||
.then(r | .then(function (r) { return r.json() }) | ||
.then( | .then(function (data) { | ||
if (data.query) { | if (data.query) { | ||
if (data.query.pages) { | if (data.query.pages) { | ||
| 第57行: | 第55行: | ||
} | } | ||
} else { | } else { | ||
useMockData() | useMockData() | ||
} | } | ||
} else { | } else { | ||
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 = [] | ||
const rows = wikitext.split('|-') | const rows = wikitext.split('|-') | ||
for (let i = 1; i < rows.length; i++) { | for (let i = 1; i < rows.length; i++) { | ||
const row = rows[i] | const row = rows[i] | ||
const columns = row.split('\n').filter(function (col) { return col.trim().startsWith('|') }) | |||
const columns = row.split('\n').filter(col | |||
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() | ||
} | } | ||
if (song.title) { | if (song.title) { | ||
| 第117行: | 第102行: | ||
} | } | ||
} | } | ||
return songs | return songs | ||
| 第129行: | 第111行: | ||
fetch(decodedUrl) | fetch(decodedUrl) | ||
.then(r | .then(function (r) { return r.json() }) | ||
.then(data | .then(function (data) { | ||
const pages = data.query.pages | |||
const pageId = Object.keys(pages)[0] | |||
const pageData = pages[pageId] | |||
if (!pageData.revisions) { | |||
throw new Error('页面不存在') | |||
} | |||
const wikitext = pageData.revisions[0]['*'] | |||
const styles = parseStylesFromWikitext(wikitext) | |||
let imageUrl = null | |||
if (pageData.thumbnail) { | |||
if (pageData.thumbnail.source) { | |||
imageUrl = pageData.thumbnail.source | |||
} | } | ||
} | |||
updateSongInfo(song, { | |||
titleStyle: styles.title || '#94E1FF', | |||
headerStyle: styles.header || '#A3E5FF', | |||
labelStyle: styles.label || '#B2E9FE', | |||
imageUrl: imageUrl, | |||
pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}` | |||
}) | |||
} | |||
}) | }) | ||
.catch(e | .catch(function (e) { | ||
console.error('获取曲目颜色失败:', e) | console.error('获取曲目颜色失败:', e) | ||
updateSongInfo(song, { | updateSongInfo(song, { | ||
| 第173行: | 第149行: | ||
}) | }) | ||
}) | }) | ||
} | } | ||
function parseStylesFromWikitext(wikitext) { | function parseStylesFromWikitext(wikitext) { | ||
const styles = {} | const styles = {} | ||
const | const color1Match = wikitext.match(/\|color1\s*=\s*([^\n}]+)/) | ||
const color3Match = wikitext.match(/\|color3\s*=\s*([^\n}]+)/) | |||
const color4Match = wikitext.match(/\|color4\s*=\s*([^\n}]+)/) | |||
const | |||
if (color1Match) styles.title = color1Match[1].trim() | |||
if ( | if (color3Match) styles.header = color3Match[1].trim() | ||
if (color4Match) styles.label = color4Match[1].trim() | |||
return styles | return styles | ||
} | } | ||
| 第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 | ||
var labelElements = document.querySelectorAll('.infobox-label') | |||
container.innerHTML = | for (var i = 0; i < labelElements.length; i++) { | ||
labelElements[i].style.background = data.labelStyle | |||
} | |||
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) { | ||
var colors = { EZ: '#57E4C4', HD: '#FDBA61', IN: '#FE8661' } | |||
return | 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() { | ||
var speeds = Array(40).fill("无限制").concat(Array.from({ length: 91 }, function (_, i) { return (i + 10) / 10 })) | |||
var mods = ["无MOD", "无MOD", "无MOD", "镜像模式", "保护模式", "Bad保护模式", "特殊计量条", "隐藏计量条"] | |||
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)] | ||
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 { | ||
var availableMods = mods.filter(function (m) { return m !== "无MOD" }) | |||
var shuffled = availableMods.slice().sort(function () { return 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)) | ||
var hasSpecial = selectedMods.includes("特殊计量条") | |||
if (hasSpecial) { | if (hasSpecial) { | ||
var specialRates = ["特殊计量条100%", "特殊计量条110%", "特殊计量条120%"] | |||
selectedMods = selectedMods.filter(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)]) | ||
} | } | ||
} | } | ||
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 = | modElement.innerHTML = '<p>' + selectedMods.join('<br>') + '</p>' | ||
} | } | ||
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 { | ||
var availableOthers = others.filter(function (o) { return o !== "无限制" }) | |||
var shuffledOthers = availableOthers.slice().sort(function () { return Math.random() - 0.5 }) | |||
var otherCount = Math.floor(Math.random() * 2) + 2 | |||
selectedOthers = | selectedOthers = shuffledOthers.slice(0, Math.min(otherCount, availableOthers.length)) | ||
} | } | ||
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 = | 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