-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move function to get page mod info into a separate file and get more …
…info about the mods
- Loading branch information
1 parent
496c056
commit 2eb1472
Showing
4 changed files
with
53 additions
and
32 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
let mods: ModObject[] | null = null; | ||
|
||
export interface ModObject { | ||
element: HTMLElement; | ||
id: string; | ||
title: string; | ||
version: string; | ||
author: string; | ||
description: string; | ||
download: string; | ||
source: string | null | ||
funding: string[] | ||
} | ||
|
||
/** | ||
* Searches the page for mod-card elements and returns information about the mods within. | ||
* | ||
* @returns An array of mod information | ||
*/ | ||
export function getModInfo(): ModObject[] { | ||
if (mods === null) { | ||
mods = ([...document.querySelectorAll<HTMLElement>("mod-card")].map( | ||
(card) => ({ | ||
element: card, | ||
id: (card.dataset.modId || "").toLowerCase(), | ||
title: ( | ||
card.querySelector<HTMLElement>("mod-name")?.innerText || "" | ||
).toLowerCase(), | ||
version: ( | ||
card.querySelector<HTMLElement>("mod-version")?.innerText || "" | ||
).toLowerCase(), | ||
author: ( | ||
card.querySelector<HTMLElement>("mod-author")?.innerText || "" | ||
).toLowerCase(), | ||
description: ( | ||
card.querySelector<HTMLElement>("mod-description")?.innerText || "" | ||
).toLowerCase(), | ||
download: card.querySelector<HTMLAnchorElement>("a.mod-download")!.href, | ||
source: card.querySelector<HTMLAnchorElement>("a.mod-source")?.href || null, | ||
funding: [...card.querySelectorAll<HTMLAnchorElement>("a.funding-link")].map(link => link.href) | ||
}) | ||
)); | ||
} | ||
|
||
return mods; | ||
} |