From 0a06bcb35ec93f32bfeed48bf6ee9defc6db92ec Mon Sep 17 00:00:00 2001 From: Gwen Malmquist Date: Fri, 26 Apr 2024 02:05:56 +0000 Subject: [PATCH] saving spell list in cookies --- pf2cards/main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pf2cards/main.js b/pf2cards/main.js index 4d689d1..0fe7232 100644 --- a/pf2cards/main.js +++ b/pf2cards/main.js @@ -1,3 +1,16 @@ +setTimeout(() => { + // read cookie + const cookies = decodeURIComponent(document.cookie); + const textbox = Array.from(new Set(Array.from(document.getElementsByClassName('spellnames'))))[0]; + for (const cookie of cookies.split(";")) { + const parts = cookie.split("="); + if (parts.length > 0 && parts[0].trim() == "names") { + textbox.value = JSON.parse(parts[1].trim()).join("\n"); + break; + } + } +}, 500); + function generateCards() { const postUrl = window.location.hostname === 'gwenscode.com' ? 'https://gwen.run/pf2cards/' @@ -10,6 +23,7 @@ function generateCards() { .map(e => e.trim().toLocaleLowerCase()) .filter(e => e.length > 0))); names.sort(); + document.cookie = "names=" + JSON.stringify(names) + ";"; document.write('Loading, this may take several seconds ...'); fetch(postUrl, { method: 'POST',