fix: hs2 last update page count

This commit is contained in:
mehbark 2024-06-12 19:59:50 -04:00
parent b3f5dbe0a4
commit fe18e92891

View file

@ -22,7 +22,7 @@ async function get_last_update_date(): Promise<
{ last_updated: Date; last_update_count: number } | string { last_updated: Date; last_update_count: number } | string
> { > {
try { try {
const res = await fetch("https://homestuck2.com/log"); const res = await fetch("https://homestuck2.com/story/log");
const body = await res.text(); const body = await res.text();
if (!body) return "couldn't get a string body"; if (!body) return "couldn't get a string body";
@ -32,14 +32,18 @@ async function get_last_update_date(): Promise<
const time = doc.querySelector("time"); const time = doc.querySelector("time");
if (!time) return "couldn't get even a single time from the doc (bad!)"; if (!time) return "couldn't get even a single time from the doc (bad!)";
console.log(time.attributes.getNamedItem("datetime")?.value);
const datetime = time.attributes.getNamedItem("datetime")?.value; const datetime = time.attributes.getNamedItem("datetime")?.value;
if (!datetime) return "time didn't have datetime attr??"; if (!datetime) return "time didn't have datetime attr??";
const date = new Date(datetime); const date = new Date(datetime);
// should work until the year 10000
// includes the hour for safety (NVM: WHAT IF IT ROLLED OVER (ugh let's hope that doesn't happen for the day))
const date_prefix = date.toISOString().slice(0, 10);
return { return {
last_updated: date, last_updated: date,
last_update_count: last_update_count:
doc.querySelectorAll(`time[datetime="${date.toISOString()}"]`) doc.querySelectorAll(`time[datetime^="${date_prefix}"]`)
.length, .length,
}; };
} catch (e) { } catch (e) {