Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist low contrast setting across routes #171

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/components/parts/install/InstallerVersion.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
</script>
</div>
20 changes: 9 additions & 11 deletions src/script.ts
Original file line number Diff line number Diff line change
@@ -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());
};