From 8b8e5da8832955dd476352c41303859e722a58ac Mon Sep 17 00:00:00 2001 From: Ibrahim Hussein <74113881+ibby9902@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:16:40 +0100 Subject: [PATCH 1/2] Remove event handler --- src/script.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/script.ts b/src/script.ts index 2346e7de4..4faaf439c 100644 --- a/src/script.ts +++ b/src/script.ts @@ -1,16 +1,14 @@ export {}; -document.body.onload = () => { - const lowContrast = document.getElementById( - "low-contrast" - ) as HTMLInputElement; - const lowContrastState = localStorage.getItem("lowContrast"); +const lowContrast = document.getElementById( + "low-contrast" +) as HTMLInputElement; +const lowContrastState = localStorage.getItem("lowContrast"); - if (lowContrastState) { - lowContrast.checked = lowContrastState == "true"; - } +if (lowContrastState) { + lowContrast.checked = lowContrastState == "true"; +} - lowContrast.onchange = () => { - localStorage.setItem("lowContrast", lowContrast.checked.toString()); - }; +lowContrast.onchange = () => { + localStorage.setItem("lowContrast", lowContrast.checked.toString()); }; From 9358829bc867c179e823f1460af61fcba9d8c736 Mon Sep 17 00:00:00 2001 From: Ibby Date: Mon, 16 Oct 2023 18:30:33 +0100 Subject: [PATCH 2/2] add fetch try-catch --- .../parts/install/InstallerVersion.astro | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/parts/install/InstallerVersion.astro b/src/components/parts/install/InstallerVersion.astro index a0ad12e14..a2959de40 100644 --- a/src/components/parts/install/InstallerVersion.astro +++ b/src/components/parts/install/InstallerVersion.astro @@ -15,14 +15,18 @@ import { t } from "i18next"; const INSTALLER_URL_BASE = "https://maven.quiltmc.org/repository/release/org/quiltmc/quilt-installer/"; const MAVEN_METADATA_URL = INSTALLER_URL_BASE + "maven-metadata.xml"; - - const metadataRequest = await fetch(MAVEN_METADATA_URL, { headers: { "User-Agent": "QuiltMC Website API" } }) - const metadata = await metadataRequest.text() - const allVersion = Array.from(metadata.matchAll(VERSION_REGEX)).map(match => match[1]) - const latest = semverSort.desc(allVersion)[0] - - if (document.getElementById("installer-version")) { - document.getElementById("installer-version").textContent = latest; + try { + const metadataRequest = await fetch(MAVEN_METADATA_URL, { headers: { "User-Agent": "QuiltMC Website API" } }) + const metadata = await metadataRequest.text() + const allVersion = Array.from(metadata.matchAll(VERSION_REGEX)).map(match => match[1]) + const latest = semverSort.desc(allVersion)[0] + + if (document.getElementById("installer-version")) { + document.getElementById("installer-version").textContent = latest; + } + } + catch(error) { + console.log(error) }