微件:CharacterAttributes:修订间差异
无编辑摘要 标签:已被回退 |
无编辑摘要 标签:已被回退 |
||
第2行: | 第2行: | ||
<div> | <div> | ||
<label for="levelSlider">角色等级: <span id="currentLevel">1</span></label> | <label for="levelSlider">角色等级: <span id="currentLevel">1</span></label> | ||
<input type="range" id="levelSlider" min="1" max=" | <input type="range" id="levelSlider" min="1" max="100" value="1"> | ||
</div> | </div> | ||
<div id="attributes"> | <div id="attributes"> | ||
第13行: | 第13行: | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function() { | ||
const characterName = '{{{characterName}}}'; // 从模板参数中获取角色名 | const characterName = '{{{characterName}}}'; // 从模板参数中获取角色名 | ||
console.log('Character Name:', characterName); | |||
// | // 构造API请求URL | ||
const | const apiUrl = `/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Data:${characterName}/属性`; | ||
fetch( | fetch(apiUrl) | ||
.then(response => response.json()) | .then(response => response.json()) | ||
.then(data => { | .then(data => { | ||
// 提取页面内容 | |||
const pages = data.query.pages; | |||
const page = pages[Object.keys(pages)[0]]; | |||
const content = page.revisions[0]['*']; | |||
console.log('Page Content:', content); | |||
// 解析JSON内容 | |||
let jsonData; | |||
try { | |||
jsonData = JSON.parse(content); | |||
console.log('Parsed JSON:', jsonData); | |||
} catch (e) { | |||
console.error('Error parsing JSON:', e); | |||
return; | |||
} | |||
const levelSlider = document.getElementById('levelSlider'); | const levelSlider = document.getElementById('levelSlider'); | ||
const currentLevel = document.getElementById('currentLevel'); | const currentLevel = document.getElementById('currentLevel'); | ||
第30行: | 第47行: | ||
currentLevel.textContent = level; | currentLevel.textContent = level; | ||
const attributes = | const attributes = jsonData.levels[level]; | ||
if (attributes) { | if (attributes) { | ||
health.textContent = attributes.health; | health.textContent = attributes.health; |