Created
January 16, 2024 04:57
-
-
Save tigersoldier/5103914062dfb3492770692f1a883c78 to your computer and use it in GitHub Desktop.
获取原神摹本摆设
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 查询摹本所需摆设并转换成CSV | |
* | |
* 用法:在浏览器登录 hoyolab,打开 devtool 的 console,运行 | |
* | |
* ``` | |
* let code = 12345; // | |
* await formatBlueprint(code); | |
* ``` | |
*/ | |
async function formatBlueprint(code) { | |
try { | |
const response = await fetch( | |
`https://sg-public-api.hoyolab.com/event/calculateos/furniture/blueprint?share_code=${code}®ion=os_usa&lang=zh-cn`, | |
{ | |
"credentials": "include", | |
}); | |
if (!response.ok) { | |
throw new Error(`HTTP error! status: ${response.status}`); | |
} | |
const jsonData = await response.json(); | |
console.info(jsonData); | |
const rows = []; | |
// rows.push('摹数,材料,数量'); | |
for (let data of jsonData.data.list) { | |
rows.push(`${code},${data.name},${data.num}`); | |
} | |
const ret = rows.join('\n'); | |
console.info(ret); // This is easier to copy | |
return ret; | |
} catch (error) { | |
console.error('Error fetching JSON:', error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment