diff options
| -rw-r--r-- | frontend/index.js | 8 | ||||
| -rw-r--r-- | frontend/main.js | 26 | ||||
| -rw-r--r-- | frontend/start.js | 15 |
3 files changed, 35 insertions, 14 deletions
diff --git a/frontend/index.js b/frontend/index.js index a392eb8..7dc741e 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -3,6 +3,12 @@ if (Array.isArray(timers[1]) && timers[1].length > 0) { window.location.href = './timer/'; } else { - window.location.href = './status/'; + const urlCookie = await cookieStore.get("last_used_url"); + + if (urlCookie) { + window.location.href = `./start/?machine_id=${urlCookie}`; + } else { + window.location.href = './status/' + } } })(); diff --git a/frontend/main.js b/frontend/main.js index 3f5c4c4..3ce5fb1 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -31,24 +31,26 @@ async function subscribe() { userVisibleOnly: true, applicationServerKey: urlBase64ToUint8Array(PUBLIC_VAPID_KEY), }); + console.log(subscription); + + console.log("sw regis pass, write to db"); + + const db_reply = await fetch(`${API_URL}/notifsubscribe`, { + method: 'POST', + credentials: "include", + body: JSON.stringify(subscription), + headers: { + "Content-Type": "application/json", + }, + }); + + return db_reply.status == 2000; } catch (e) { console.log("ERR in regis, ", e); return false; } - console.log("sw regis pass, write to db"); - - const db_reply = await fetch(`${API_URL}/notifsubscribe`, { - method: 'POST', - credentials: "include", - body: JSON.stringify(subscription), - headers: { - "Content-Type": "application/json", - }, - }); - - return db_reply.status == 2000; } /// copied from somewhere diff --git a/frontend/start.js b/frontend/start.js index 3d76e53..608ed9e 100644 --- a/frontend/start.js +++ b/frontend/start.js @@ -2,7 +2,7 @@ const startbtn = document.getElementById("startbtn"); const urlParams = new URLSearchParams(window.location.search); data.machine_id = urlParams.get('machine'); -//remember +rememberUrl(); console.log(urlParams); startUpdateMachines(); @@ -49,3 +49,16 @@ startUpdateMachines(); startbtn.addEventListener("click", () => { start(); }); + +function rememberUrl() { + machineId = urlParams.get('machine'); + minutesDelta = 5; + expirationDate = new Date(date.getTime() + minutesDelta * 60000);; + browser.cookies.set({ + expirationDate: expirationDate.getTime(), + name: "last_used_url", + value: machineId, + url: "https://laundryweb.altafcreator.com", + secure: true, + }) +} |
