This commit is contained in:
quenousimporte 2025-03-11 11:42:10 +01:00
parent 972653f159
commit c55a5263bf
1 changed files with 16 additions and 33 deletions

49
jrpg.ts
View File

@ -7,6 +7,11 @@ function getdompareser(html)
return parser.parseFromString(html, "text/html") return parser.parseFromString(html, "text/html")
} }
function gettables(doc)
{
return [...doc.getElementsByTagName("h2")].map(h2 => h2.id)
}
function getcategory(doc, category, notes) function getcategory(doc, category, notes)
{ {
const result = [] const result = []
@ -36,14 +41,17 @@ function getcategory(doc, category, notes)
function getnotes(doc) function getnotes(doc)
{ {
return []
const lastsup = [...doc.getElementsByTagName("sup")].pop() const lastsup = [...doc.getElementsByTagName("sup")].pop()
if (!lastsup)
{
return []
}
return lastsup.parentElement.textContent.split("\n") return lastsup.parentElement.textContent.split("\n")
.filter(i => i.length) .filter(i => i.length)
.map(i => i.substr(3)) .map(i => i.substr(3))
} }
async function getpage(url, tables) async function getpage(url)
{ {
const result = {} const result = {}
const response = await fetch(url) const response = await fetch(url)
@ -51,7 +59,7 @@ async function getpage(url, tables)
const doc = getdompareser(html) const doc = getdompareser(html)
const notes = getnotes(doc) const notes = getnotes(doc)
const tables = gettables(doc)
tables.forEach(category => tables.forEach(category =>
{ {
result[category] = getcategory(doc, category, notes) result[category] = getcategory(doc, category, notes)
@ -64,9 +72,8 @@ function format(equipment)
const result = [] const result = []
const exclude = ["Found", "Sold", "Available", "Ft","Mr","Go"] const exclude = ["Found", "Sold", "Available", "Ft","Mr","Go"]
// todo: notes as footers instead of column
// todo: put excludes in config // todo: put excludes in config
// todo: fix footer notes
// todo: guess tables list
// todo: invert available X mark // todo: invert available X mark
// todo: remove a column if always empty // todo: remove a column if always empty
@ -123,7 +130,7 @@ async function getdata(configname)
for (const index in pages) for (const index in pages)
{ {
const page = pages[index] const page = pages[index]
const pagedata = await getpage([root, configname, page.url].join("/"), page.tables) const pagedata = await getpage([root, configname, page].join("/") + ".html")
result = {...result, ...pagedata} result = {...result, ...pagedata}
} }
return result return result
@ -135,35 +142,11 @@ function output(string)
} }
const configs = { const configs = {
ffantasy: [ ffantasy: ["weapons", "armor", "blackmagic", "whitemagic"],
{ dw3: ["armor", "weapons"]
url: "weapons.html",
tables: ["swords", "axes", "daggers", "staffs", "hammers", "nunchucks", "miscellaneous"]
},
{
url: "armor.html",
tables: ["armor", "braceletes", "shields", "helmets", "gauntlets"]
},
{
url: "blackmagic.html",
tables: ["black_magic"]
},
{
url: "whitemagic.html",
tables: ["white_magic"]
}],
dw3: [
{
url: "armor.html",
tables: ["armor", "shields", "helmets"]
},
{
url: "weapons.html",
tables: ["weapons"]
}]
} }
getdata("ffantasy") getdata("dw3")
.then(format) .then(format)
.then(output) .then(output)