diff --git a/notes b/notes index 166ff95..eafa2b7 100644 --- a/notes +++ b/notes @@ -3,6 +3,7 @@ https://randoma11y.com/ https://fonts.google.com/knowledge/choosing_type https://www.goatcounter.com/ https://web.dev/articles/optimize-webfont-loading +https://tinylytics.app/ noted fonts: Moderat mono https://tightype.com/typefaces/moderat-mono diff --git a/static/demos/light-dark-demo-4/index.html b/static/demos/light-dark-demo-4/index.html index 8cdc520..bef5017 100644 --- a/static/demos/light-dark-demo-4/index.html +++ b/static/demos/light-dark-demo-4/index.html @@ -68,10 +68,10 @@ await navigator.serviceWorker.register("sw.js");

Here is some example text

-
+
-
+
diff --git a/static/demos/light-dark-demo-4/sw.js b/static/demos/light-dark-demo-4/sw.js index 9587453..db0a563 100644 --- a/static/demos/light-dark-demo-4/sw.js +++ b/static/demos/light-dark-demo-4/sw.js @@ -6,10 +6,13 @@ self.addEventListener("fetch", event =>{ event.respondWith((async ()=>{ const resp = await fetch(event.request); const body = await resp.text(); - return new Response(body.replace("", ''), { - headers:resp.headers, - status: resp.status - }); + const url = new URL(event.request.url); + if(url.pathname.endsWith("light-dark-toggle")){ + return await handle_redirect(req); + } + else { + return await handle_html(req,resp); + } })()); }) @@ -34,7 +37,14 @@ async function handle_redirect(req){ transaction.commit(); }; }; - await Promise.all([up_promise, suc_promise]) + await Promise.all([up_promise, suc_promise]); + const referrer = request.headers.get('Referer') || '/'; + return new Response("You should be getting redirected back to the page you came from shortly",{ + status: 302, + headers: { + 'Location': referrer + } + }) } function IDB_cond_create(db, objectStoreName, opts={}){ return new Promise((res)=>{ @@ -61,6 +71,21 @@ function toggleLightDark(transaction){ }); } -async function handle_html(req){ +async function handle_html(req, resp){ // TODO: read from indexDB to figure out if we fiddle with the body classes or not + const obj_store = transaction.objectStore("light-dark-store"); + const grab = obj_store.get(1); + const toggled = await (new Promise((res)=>{ + grab.onsuccess = (event)=>{ + const val = event.result; + const toggled = !!val; + res(toggled); + } + })); + if(!toggled) return resp; + + return new Response(body.replace("", ''), { + headers:resp.headers, + status: resp.status + }); }