From be1fe9728d82b035033be84ccae01579bc13d19b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 22 Feb 2024 23:03:29 -0800 Subject: use cookies for pin memory --- src/lib/utils.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/lib/utils.js') diff --git a/src/lib/utils.js b/src/lib/utils.js index 9f9fc042..8e3ff004 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -223,6 +223,7 @@ export let sats = 100000000; export let back = () => browser && (history.length ? history.go(-1) : goto("/")); + export let focus = (el) => browser && screen.width > 1280 && setTimeout(() => el.focus(), 1); @@ -316,3 +317,21 @@ export let isLiquid = (text) => (text.startsWith("ex1q") && text.length === 42) || text.startsWith("el1qq") || text.startsWith("lq1qq"); + +export function getCookie(name) { + let nameEQ = name + "="; + let ca = document.cookie.split(";"); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) === " ") c = c.substring(1); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); + } + return null; +} + +export function setCookie(name, value, seconds) { + const now = new Date(); + now.setTime(now.getTime() + seconds * 1000); + const expires = "expires=" + now.toUTCString(); + document.cookie = name + "=" + value + ";" + expires + ";path=/"; +} -- cgit v1.2.3