用户:RedDragon/Test2:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第36行: | 第36行: | ||
<script> | <script> | ||
document.addEventListener('DOMContentLoaded', () => { | document.addEventListener('DOMContentLoaded', () => { | ||
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. | .then(r => r.json()) | ||
.then( | .then(data => { | ||
console.log(' | console.log('解析后的数据:', data) | ||
const | if (data.query) { | ||
if (data.query.pages) { | |||
const pages = data.query.pages | |||
const pageId = Object.keys(pages)[0] | |||
const wikitext = pages[pageId].revisions[0]['*'] | |||
const songs = parseSongsFromWikitext(wikitext) | |||
if (songs.length > 0) { | |||
loadSongColors(songs[Math.floor(Math.random() * songs.length)]) | |||
if ( | |||
} else { | } else { | ||
useMockData() | useMockData() | ||
} | } | ||
} | } else { | ||
console.error(' | console.error('数据格式不正确,缺少query.pages') | ||
useMockData() | useMockData() | ||
} | } | ||
} else { | } else { | ||
console.error(' | console.error('数据格式不正确,缺少query') | ||
useMockData() | useMockData() | ||
} | } | ||
| 第116行: | 第95行: | ||
} | } | ||
function loadSongColors(song) { | |||
const encodedUrl = `https://rizwiki.cn/api.php?action=query%26titles=${encodeURIComponent(song.title)}%26prop=revisions%26rvprop=content%26format=json` | const encodedUrl = `https://rizwiki.cn/api.php?action=query%26titles=${encodeURIComponent(song.title)}%26prop=revisions%26rvprop=content%26format=json` | ||
const decodedUrl = decodeURIComponent(encodedUrl) | const decodedUrl = decodeURIComponent(encodedUrl) | ||
fetch(decodedUrl) | fetch(decodedUrl) | ||
.then(r => r. | .then(r => r.json()) | ||
.then( | .then(data => { | ||
const | try { | ||
const pages = data.query.pages | |||
const pageId = Object.keys(pages)[0] | |||
if (!pages[pageId].revisions) { | |||
throw new Error('页面不存在') | |||
} | |||
const wikitext = pages[pageId].revisions[0]['*'] | |||
const styles = parseStylesFromWikitext(wikitext) | |||
updateSongInfo(song, { | |||
titleStyle: styles.title || '#94E1FF', | |||
headerStyle: styles.header || '#A3E5FF', | |||
labelStyle: styles.label || '#B2E9FE', | |||
imageUrl: `https://rizwiki.cn/images/thumb/${song.image.substring(0, 1)}/${song.image.substring(0, 2)}/${song.image}/300px-${song.image}`, | |||
pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}` | |||
}) | |||
} catch (e) { | |||
console.error('解析曲目数据失败:', e) | |||
throw e | |||
} | } | ||
}) | }) | ||
2025年10月19日 (日) 22:57的版本
| 曲目 | |
|---|---|
|
|
|
| 限制 | |
| 难度 | a |
| 流速 | b |
| MOD | c |
| 其他 | d |
神秘的随机挑战!
| 曲目 | |
|---|---|
|
| |
| 限制 | |
| 难度 | a |
| 流速 | b |
| MOD | c |
| 其他 | d |
User:RedDragon/Test User:RedDragon/Test1 User:RedDragon/Test2