import { email } from "https://esm.town/v/std/email";
import { md5 } from "https://esm.town/v/tr3ntg/md5?v=1";
export async function download() {
const URL = "https://www.knvbshop.nl/nike-nederlands-elftal-thuisshirt-2024-2026.html#size=XL";
const unless = [
">XL <span class=\"sep\">-</span> <span class=\"label\">Niet op voorraad",
">XL <span class=\"sep\">-</span> <span class=\"label\">Verwacht op",
];
const now = new Date();
let ok = false;
let res;
let reason: string;
try {
res = await fetch(URL, { redirect: "follow" });
if (!res.ok) {
throw await res.text();
}
ok = true;
} catch (e) {
reason = `couldn't fetch: ${e}`;
await email({ subject: "could not update the contents of the change", text: reason });
}
if (ok) {
const html = await res.text();
if (html.includes("select bd_clothing_size") && !unless.some(text => html.includes(text))) {
const subject = `Voetbal shirt available in XL!`;
await email({ subject, text: `Last check: ${now}\nLink: ${URL}\n` });
}
} else {
console.log("Maat selector not found");
}
}