Skip to content

Commit

Permalink
saving spell list in cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalmquist committed Apr 26, 2024
1 parent 805f9f8 commit 0a06bcb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pf2cards/main.js
Original file line number Diff line number Diff line change
@@ -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/'
Expand All @@ -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',
Expand Down

0 comments on commit 0a06bcb

Please sign in to comment.