functional programming

This commit is contained in:
Zynh0722 2024-04-02 19:33:13 -07:00
parent 4b9311c61f
commit f9a5d5cdac

View file

@ -14,24 +14,22 @@ async function getPatchHrefs() {
let patchHrefs: string[] = [];
for (let i = 0; i <= 7; i++) {
const req = await fetch(getGalleryPageHref(i));
const data = parse(await req.text());
[...Array(7).keys()]
.map((val) => ++val)
.map(async (page) => {
const req = await fetch(getGalleryPageHref(page));
const data = parse(await req.text());
const gallery = data
.getElementsByTagName("div")
.filter((el) => el.classList.contains("hds-gallery-items"))
.shift();
const gallery = data
.getElementsByTagName("div")
.filter((el) => el.classList.contains("hds-gallery-items"))
.shift();
const links = gallery
?.getElementsByTagName("a")
.map((el) => el.getAttribute("href"))
.filter((el) => el) as string[];
patchHrefs.push.apply(patchHrefs, links);
}
return patchHrefs;
return gallery
?.getElementsByTagName("a")
.map((el) => el.getAttribute("href"))
.filter((el) => el) as string[];
});
}
const allPatches = await getPatchHrefs();