用户:RedDragon/Test2:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第36行: | 第36行: | ||
<script> | <script> | ||
document.addEventListener('DOMContentLoaded', () => { | document.addEventListener('DOMContentLoaded', () => { | ||
fetch('https://rizwiki.cn/ | fetch('https://rizwiki.cn/api.php?action=query&titles=曲目列表&prop=revisions&rvprop=content&format=json') | ||
.then(r => r.ok ? r. | .then(r => r.ok ? r.json() : Promise.reject('网络错误')) | ||
.then( | .then(data => { | ||
const | const pages = data.query.pages | ||
const pageId = Object.keys(pages)[0] | |||
const wikitext = pages[pageId].revisions[0]['*'] | |||
const songs = parseSongsFromWikitext(wikitext) | |||
songs.length > 0 | songs.length > 0 | ||
| 第80行: | 第53行: | ||
}) | }) | ||
}) | }) | ||
function parseSongsFromWikitext(wikitext) { | |||
const songs = [] | |||
const rowRegex = /\{\|.*?\|\}(.*?)\|\}/gs | |||
const lineRegex = /\|\[\[文件:(.*?)\]\]\s*\|\|\s*\[\[(.*?)\]\]\s*\|\|\s*(.*?)\s*\|\|\s*(.*?)\s*\|\|\s*(\d+)\s*\|\|\s*(\d+)\s*\|\|\s*(\d+)/g | |||
let match | |||
while ((match = lineRegex.exec(wikitext)) !== null) { | |||
const song = { | |||
image: match[1], | |||
title: match[2], | |||
author: match[3], | |||
duration: match[4], | |||
ez: match[5], | |||
hd: match[6], | |||
in: match[7] | |||
} | |||
if (song.title) songs.push(song) | |||
} | |||
return songs | |||
} | |||
function loadSongColors(song) { | function loadSongColors(song) { | ||
fetch(`https://rizwiki.cn/ | fetch(`https://rizwiki.cn/api.php?action=query&titles=${encodeURIComponent(song.title)}&prop=revisions&rvprop=content&format=json`) | ||
.then(r => r.ok ? r. | .then(r => r.ok ? r.json() : Promise.reject('页面不存在')) | ||
.then( | .then(data => { | ||
const | const pages = data.query.pages | ||
const | const pageId = Object.keys(pages)[0] | ||
const | const wikitext = pages[pageId].revisions[0]['*'] | ||
const styles = parseStylesFromWikitext(wikitext) | |||
const imageUrl = parseImageFromWikitext(wikitext) | |||
updateSongInfo(song, { | updateSongInfo(song, { | ||
titleStyle: | titleStyle: styles.title || '#94E1FF', | ||
headerStyle: | headerStyle: styles.header || '#A3E5FF', | ||
labelStyle: | labelStyle: styles.label || '#B2E9FE', | ||
imageUrl: imageUrl, | imageUrl: imageUrl, | ||
pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}` | pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}` | ||
| 第110行: | 第104行: | ||
}) | }) | ||
} | } | ||
function parseStylesFromWikitext(wikitext) { | |||
const styles = {} | |||
const titleMatch = wikitext.match(/infobox-title.*?background:(#[0-9a-fA-F]+)/) | |||
if (titleMatch) styles.title = titleMatch[1] | |||
const headerMatch = wikitext.match(/infobox-header.*?background:(#[0-9a-fA-F]+)/) | |||
if (headerMatch) styles.header = headerMatch[1] | |||
const labelMatch = wikitext.match(/infobox-label.*?background:(#[0-9a-fA-F]+)/) | |||
if (labelMatch) styles.label = labelMatch[1] | |||
return styles | |||
} | |||
function parseImageFromWikitext(wikitext) { | |||
const fileMatch = wikitext.match(/\[\[文件:(.*?)\]\]/) | |||
if (fileMatch) { | |||
const fileName = fileMatch[1] | |||
return `https://rizwiki.cn/images/thumb/${fileName.substring(0, 1)}/${fileName.substring(0, 2)}/${fileName}/300px-${fileName}` | |||
} | |||
return null | |||
} | |||
function updateSongInfo(song, data) { | function updateSongInfo(song, data) { | ||
| 第203行: | 第218行: | ||
</html> | </html> | ||
神秘的随机挑战! | 神秘的随机挑战! | ||
{{Infobox | |||
|name = 随机挑战 | |||
|title = 曲目 | |||
|titlestyle = background:#ccc | |||
|image = [[File:插画图标.png|200px]] | |||
|imagestyle = | |||
|headerstyle = background:#ccf | |||
|labelstyle = background:#ddf | |||
|header1 = 限制 | |||
|label2 = 难度 | |||
|data2 = a | |||
|label3 = 流速 | |||
|data3 = b | |||
|label4 = MOD | |||
|data4 = c | |||
|label5 = 其他 | |||
|data5 = d | |||
}} | |||
---- | ---- | ||
[[User:RedDragon/Test]] | [[User:RedDragon/Test]] | ||
[[User:RedDragon/Test1]] | [[User:RedDragon/Test1]] | ||
[[User:RedDragon/Test2]] | [[User:RedDragon/Test2]] | ||
2025年10月19日 (日) 21:33的版本
| 曲目 | |
|---|---|
|
|
|
| 限制 | |
| 难度 | a |
| 流速 | b |
| MOD | c |
| 其他 | d |
神秘的随机挑战!
| 曲目 | |
|---|---|
|
| |
| 限制 | |
| 难度 | a |
| 流速 | b |
| MOD | c |
| 其他 | d |
User:RedDragon/Test User:RedDragon/Test1 User:RedDragon/Test2