feat(official_update): update to match new ak version

This commit is contained in:
Haoyu Xu
2024-05-02 13:14:40 +08:00
parent 1b782e0c7b
commit 314d0a4c7f
3 changed files with 182 additions and 144 deletions

View File

@@ -31,53 +31,63 @@ export default class OfficalInfo {
const html_text = await f.text()
const dom = new jsdom.JSDOM(html_text);
const rows = dom.window.document.body.querySelector(".dynList").querySelectorAll(".row")
const scripts = dom.window.document.body.querySelectorAll("script");
let data;
scripts.forEach((e) => {
if (e.textContent.includes("干员晋升")) {
data = JSON.parse(e.textContent.replace("self.__next_f.push([1,\"c:", "").replace("\\n\"])", "").replaceAll("\\", ""))
}
})
const rows = data[0][3].initialData
const dict = {
length: 0
length: rows.length,
dates: []
}
let current_displayTime = rows[0].displayTime
let current_block = []
for (const row of rows) {
const date = row.querySelector(".date").textContent.trim()
const operators = []
const charCards = row.querySelectorAll(".charCard")
if (dict.length === 0) {
dict.latest = date
const displayTime = row.displayTime
if (displayTime !== current_displayTime) {
dict[current_displayTime] = current_block;
dict.dates.push(current_displayTime);
current_displayTime = row.displayTime;
current_block = [];
}
for (const charCard of charCards) {
const color = charCard.style.color
const codename = {
"zh-CN": charCard.querySelector(".info").querySelector(".name").querySelector(".text").textContent.trim(),
"en-US": charCard.querySelector(".info").querySelector(".codename").textContent.trim()
}
const rawType = charCard.querySelector(".typeIcon").querySelector("svg").querySelector("use").getAttribute("xlink:href")
const link = "https://ak.hypergryph.com" + charCard.getAttribute("href")
const linkSplited = link.split("/")
const id = linkSplited[linkSplited.length - 1].replace(".html", "")
let type;
switch (rawType) {
case "#skin-type-icon-hanger":
type = "skin"
break;
case "#skin-type-icon-promotion2":
type = "operator"
break;
}
operators.push({
color,
codename,
type,
link,
id
})
dict.length++
}
dict[date] = operators
current_block.push(this.get_row(row))
}
dict[current_displayTime] = current_block;
dict.dates.push(current_displayTime);
writeSync(JSON.stringify(dict, null, 4), path.join('offical_update.json'))
}
get_row(row) {
const type = row.type;
let codename_zhCN, item_type;
switch (type) {
case 0:
codename_zhCN = row.charName
item_type = "operator"
break;
case 1:
codename_zhCN = row.suitName + " · " + row.charName
item_type = "skin"
break;
default:
throw ("unknown type");
}
return {
color: null,
codename: {
"zh-CN": codename_zhCN,
"en-US": row.codename
},
type: item_type,
link: `https://ak.hypergryph.com/archive/dynamicCompile/${row.cid}.html`,
id: row.cid
}
}
}