用户:RedDragon/Test2:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第127行: | 第127行: | ||
function loadSongColors(song) { | function loadSongColors(song) { | ||
console.log(' | console.log('正在获取曲目颜色和图片:', song.title); | ||
fetch(`https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`) | fetch(`https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}`) | ||
.then(response => { | .then(response => { | ||
| 第141行: | 第140行: | ||
const doc = parser.parseFromString(html, 'text/html') | const doc = parser.parseFromString(html, 'text/html') | ||
const titleElem = doc.querySelector('.infobox-title th') | |||
const titleElem = doc.querySelector('.infobox-title') | const headerElem = doc.querySelector('.infobox-header th') | ||
const headerElem = doc.querySelector('.infobox-header') | |||
const labelElem = doc.querySelector('.infobox-label') | const labelElem = doc.querySelector('.infobox-label') | ||
const titleStyle = titleElem ? titleElem.style. | const titleStyle = titleElem ? titleElem.style.background : null | ||
const headerStyle = headerElem ? headerElem.style. | const headerStyle = headerElem ? headerElem.style.background : null | ||
const labelStyle = labelElem ? labelElem.style. | const labelStyle = labelElem ? labelElem.style.background : null | ||
console.log('获取到的颜色:', { titleStyle, headerStyle, labelStyle }) | console.log('获取到的颜色:', { titleStyle, headerStyle, labelStyle }) | ||
const imgElem = doc.querySelector('.infobox img') | |||
let imageUrl = null | |||
if (imgElem) { | |||
imageUrl = imgElem.src || imgElem.getAttribute('data-src') | |||
if (imageUrl && imageUrl.startsWith('/')) { | |||
imageUrl = 'https://rizwiki.cn' + imageUrl | |||
} | |||
} | |||
updateSongInfo(song, { | updateSongInfo(song, { | ||
titleStyle: titleStyle || '#94E1FF', | titleStyle: titleStyle || '#94E1FF', | ||
headerStyle: headerStyle || '#A3E5FF', | headerStyle: headerStyle || '#A3E5FF', | ||
labelStyle: labelStyle || '#B2E9FE' | labelStyle: labelStyle || '#B2E9FE', | ||
imageUrl: imageUrl, | |||
pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}` | |||
}) | }) | ||
}) | }) | ||
| 第163行: | 第172行: | ||
titleStyle: '#94E1FF', | titleStyle: '#94E1FF', | ||
headerStyle: '#A3E5FF', | headerStyle: '#A3E5FF', | ||
labelStyle: '#B2E9FE' | labelStyle: '#B2E9FE', | ||
imageUrl: null, | |||
pageUrl: `https://rizwiki.cn/wiki/${encodeURIComponent(song.title)}` | |||
}) | }) | ||
}) | }) | ||
| 第190行: | 第201行: | ||
} | } | ||
function updateSongInfo(song, | function updateSongInfo(song, data) { | ||
const titleElement = document.querySelector('.infobox-title th') | const titleElement = document.querySelector('.infobox-title th') | ||
titleElement.textContent = song.title | titleElement.textContent = song.title | ||
titleElement.style.background = | titleElement.style.background = data.titleStyle | ||
const imageContainer = document.querySelector('.infobox td[colspan="2"]') | |||
let imageElement = document.getElementById('song-image') | |||
const imageElement = document. | if (!imageElement || data.imageUrl) { | ||
imageContainer.innerHTML = '' | |||
if (imageUrl. | const imageLink = document.createElement('a') | ||
imageLink.href = data.pageUrl | |||
} else | imageLink.target = '_blank' | ||
imageElement = document.createElement('img') | |||
imageElement.id = 'song-image' | |||
imageElement.width = 200 | |||
imageElement.height = 200 | |||
if (data.imageUrl) { | |||
console.log('设置图片URL:', data.imageUrl) | |||
imageElement.src = data.imageUrl | |||
} else { | |||
console.log('未找到图片,使用默认图片') | |||
imageElement.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' | |||
} | } | ||
imageLink.appendChild(imageElement) | |||
imageContainer.appendChild(imageLink) | |||
} | } | ||
document.querySelector('.infobox-header th').style.background = | document.querySelector('.infobox-header th').style.background = data.headerStyle | ||
const labelElements = document.querySelectorAll('.infobox-label') | const labelElements = document.querySelectorAll('.infobox-label') | ||
labelElements.forEach(label => { | labelElements.forEach(label => { | ||
label.style.background = | label.style.background = data.labelStyle | ||
}) | }) | ||
window.difficultyArray = [ | window.difficultyArray = [ | ||
createDiffSpan("EZ", song.ez), | createDiffSpan("EZ", song.ez), | ||