mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-07-29 11:09:51 +00:00
Update interfaces
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
import { Page } from "puppeteer-core"
|
||||
|
||||
enum Category {
|
||||
POKEMON,
|
||||
TRAINER,
|
||||
@ -12,6 +10,12 @@ const en = [
|
||||
"Energy"
|
||||
]
|
||||
|
||||
const fr = [
|
||||
"Pokémon",
|
||||
"Dresseur",
|
||||
"Énergie"
|
||||
]
|
||||
|
||||
namespace Category {
|
||||
export function fromEnglish(str: string) {
|
||||
let i = en.indexOf(str)
|
||||
@ -20,38 +24,14 @@ namespace Category {
|
||||
return i
|
||||
}
|
||||
|
||||
export function toLang(i: Category, lang: string) {
|
||||
export function toLang(i: Category, lang: string): string {
|
||||
switch (lang) {
|
||||
case "en":
|
||||
return en[i]
|
||||
default:
|
||||
break;
|
||||
case "fr":
|
||||
return fr[i]
|
||||
}
|
||||
}
|
||||
export async function detect(tab: Page): Promise<Category> {
|
||||
const type = await tab.$eval(".card-basic-info .card-type h2", (el: HTMLElement) => {
|
||||
return el.innerText
|
||||
})
|
||||
if (
|
||||
type.startsWith("Dresseur") ||
|
||||
type.startsWith("Trainer") ||
|
||||
type.startsWith("Entrenador")
|
||||
) {
|
||||
return Category.TRAINER
|
||||
}
|
||||
if (
|
||||
type.startsWith("Énergie") ||
|
||||
type.endsWith("Energy") ||
|
||||
type.startsWith("Energía")
|
||||
) {
|
||||
return Category.ENERGY
|
||||
}
|
||||
try {
|
||||
await tab.$(".pokemon-stats .stat:nth-child(3)")
|
||||
return Category.POKEMON
|
||||
} catch {}
|
||||
console.log(tab.url())
|
||||
throw new Error("Pokemon Category not found !")
|
||||
throw new Error(`Error, Language not implemented! (${lang})`)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user