Compare commits
No commits in common. "8298e7d098fec8c3dcd35780da4eaa741c110b11" and "0d2cc5a3543439605002fea2d0b9affedc288813" have entirely different histories.
8298e7d098
...
0d2cc5a354
3 changed files with 35 additions and 36 deletions
|
@ -70,10 +70,10 @@
|
||||||
await navigator.serviceWorker.register("sw.js");
|
await navigator.serviceWorker.register("sw.js");
|
||||||
</script>
|
</script>
|
||||||
<p>Here is some example text</p>
|
<p>Here is some example text</p>
|
||||||
<form action="./light-dark-toggle" method="get">
|
<form action="/light-dark-toggle" method="get">
|
||||||
<input id="full-demo" type="submit" value="Fully enhanced demo">
|
<input id="full-demo" type="submit" value="Fully enhanced demo">
|
||||||
</form>
|
</form>
|
||||||
<form action="./light-dark-toggle" method="get">
|
<form action="/light-dark-toggle" method="get">
|
||||||
<input id="min-demo" type="submit" value="No javascript simulation">
|
<input id="min-demo" type="submit" value="No javascript simulation">
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -9,7 +9,6 @@ self.addEventListener("fetch", event =>{
|
||||||
const resp3 = resp2.clone();
|
const resp3 = resp2.clone();
|
||||||
const body = await resp2.text();
|
const body = await resp2.text();
|
||||||
const url = new URL(event.request.url);
|
const url = new URL(event.request.url);
|
||||||
console.log(url.pathname);
|
|
||||||
if(url.pathname.endsWith("light-dark-toggle")){
|
if(url.pathname.endsWith("light-dark-toggle")){
|
||||||
return await handle_redirect(event.request);
|
return await handle_redirect(event.request);
|
||||||
}
|
}
|
||||||
|
@ -25,13 +24,13 @@ async function handle_redirect(req){
|
||||||
const up_promise = new Promise((res)=>{
|
const up_promise = new Promise((res)=>{
|
||||||
db_req.onupgradeneeded = (event) => {
|
db_req.onupgradeneeded = (event) => {
|
||||||
const db = event.target.result;
|
const db = event.target.result;
|
||||||
IDB_cond_create(db, "light-dark-store", {keyPath: 'id'}).then(res);
|
IDB_cond_create(db, "light-dark-store", {}).then(res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const suc_promise = new Promise((res)=>{
|
const suc_promise = new Promise((res)=>{
|
||||||
db_req.onsuccess = (event) => {
|
db_req.onsuccess = (event) => {
|
||||||
const db = event.target.result;
|
const db = event.target.result;
|
||||||
const transaction = db.transaction("light-dark-store", "readwrite");
|
const transaction = db.transaction("light-dark-store");
|
||||||
transaction.oncomplete = res;
|
transaction.oncomplete = res;
|
||||||
|
|
||||||
transaction.objectStore("light-dark-store", "readwrite");
|
transaction.objectStore("light-dark-store", "readwrite");
|
||||||
|
@ -89,7 +88,7 @@ async function handle_html(req, resp, body){
|
||||||
const transaction = db.transaction("light-dark-store");
|
const transaction = db.transaction("light-dark-store");
|
||||||
transaction.oncomplete = res;
|
transaction.oncomplete = res;
|
||||||
|
|
||||||
const obj_store = transaction.objectStore("light-dark-store", "readonly");
|
const obj_store = transaction.objectStore("light-dark-store", "read");
|
||||||
const grab = obj_store.get(1);
|
const grab = obj_store.get(1);
|
||||||
grab.onsuccess = (event) => {res(!!event.result)};
|
grab.onsuccess = (event) => {res(!!event.result)};
|
||||||
};
|
};
|
||||||
|
|
60
sw.js
60
sw.js
|
@ -1,30 +1,30 @@
|
||||||
//"use strict";
|
"use strict";
|
||||||
//
|
|
||||||
//// used so I can prompt updates to the service worker
|
// used so I can prompt updates to the service worker
|
||||||
//const version = "22-01-2025";
|
const version = "22-01-2025";
|
||||||
//
|
|
||||||
//const cache = new Cache();
|
const cache = new Cache();
|
||||||
//
|
|
||||||
//self.addEventListener("install", (event) => {
|
self.addEventListener("install", (event) => {
|
||||||
// // can't add /static/* due to demos living there
|
// can't add /static/* due to demos living there
|
||||||
// cache.addAll([
|
cache.addAll([
|
||||||
// "/",
|
"/",
|
||||||
// "/index.html",
|
"/index.html",
|
||||||
// "/static/css/*",
|
"/static/css/*",
|
||||||
// "/static/js/*",
|
"/static/js/*",
|
||||||
// "/static/images/*",
|
"/static/images/*",
|
||||||
// "/static/video/*"
|
"/static/video/*"
|
||||||
// ]);
|
]);
|
||||||
//});
|
});
|
||||||
//
|
|
||||||
//async function handleCache(event) {
|
async function handleCache(event) {
|
||||||
// const cache_value = await cache.match(event.request);
|
const cache_value = await cache.match(event.request);
|
||||||
// if (cache_value === undefined) {
|
if (cache_value === undefined) {
|
||||||
// return fetch(event.request);
|
return fetch(event.request);
|
||||||
// }
|
}
|
||||||
// return cache_value;
|
return cache_value;
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//self.addEventListener("fetch", async (event) => {
|
self.addEventListener("fetch", async (event) => {
|
||||||
// event.respondWith(handleCache(event));
|
event.respondWith(handleCache(event));
|
||||||
//});
|
});
|
||||||
|
|
Loading…
Reference in a new issue