Use localStorage for green

This commit is contained in:
pancakes 2024-12-13 01:14:17 +10:00
parent 2650d024db
commit 7a882942e6
No known key found for this signature in database
GPG key ID: ED53D426432B861B
5 changed files with 22 additions and 22 deletions

View file

@ -1,7 +0,0 @@
export async function load({ cookies }) {
const green = cookies.get("green");
return {
green: green === "true"
};
}

View file

@ -1,14 +1,17 @@
<script>
import { browser } from "$app/environment";
import { page } from "$app/stores";
import Footer from "$lib/components/Footer.svelte";
import Navbar from "$lib/components/Navbar.svelte";
import "./style.css";
export let data;
const green = browser
? window.localStorage.getItem("green") === "true"
: false;
</script>
<svelte:head>
{#if data.green}
{#if green}
<link rel="stylesheet" href="/assets/green.css" />
{/if}
<title>

16
src/routes/green/+page.js Normal file
View file

@ -0,0 +1,16 @@
import { browser } from '$app/environment';
import { redirect } from '@sveltejs/kit';
export async function load() {
if (!browser) return;
const green = window.localStorage.getItem("green");
if (green === "true") {
window.localStorage.removeItem("green");
} else {
window.localStorage.setItem("green", "true");
}
redirect(302, "/");
}

View file

@ -1,13 +0,0 @@
import { redirect } from '@sveltejs/kit';
export async function load({ cookies }) {
const green = cookies.get("green");
if (green === "true") {
cookies.delete("green", { path: "/" });
} else {
cookies.set("green", "true", { path: "/", sameSite: "strict" });
}
redirect(302, "/");
}

View file

@ -0,0 +1 @@
<p>Toggling green...</p>