Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { DOMParser } from "jsr:@b-fuze/deno-dom@0.1.47";
interface ServerInfo {
id: string;
server: string;
name: string;
description: string;
quality: string;
size?: string;
}
export async function convertHTMLToJSON(html: string): Promise<ServerInfo[]> {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
const serverList: ServerInfo[] = [];
const listItems = doc.querySelectorAll("ul.sources-list.mixed > li");
listItems.forEach(item => {
const id = item.getAttribute("data-id") || "";
const server = item.getAttribute("data-server") || "";
const name = (item.querySelector(".server-name")?.textContent || "").trim();
const description = (item.childNodes[2]?.textContent || "").trim();
const qualitySpan = item.querySelector(".quality");
const quality = (qualitySpan?.textContent || "").trim();
const size = (qualitySpan?.classList.contains("size") ? qualitySpan.textContent : undefined)?.trim();
serverList.push({
id,
server,
name,
description,
quality,
size,
});
});
return serverList;
}
July 26, 2024