diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2026-05-03 08:18:20 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2026-05-03 08:18:20 -0400 |
| commit | ac7031554f3be0219e6fabf39e93ce8e001b69c8 (patch) | |
| tree | 85afc9a74127799f82f7b9c2acd3d1d4253ef20c | |
| parent | 3ede872584547a1628df3026c1b466eb4db093ef (diff) | |
Add an escape hatch to save the deck state in case of errorcgi-storage
| -rw-r--r-- | srs-anywhere-network.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/srs-anywhere-network.js b/srs-anywhere-network.js index 3687402..ac92a82 100644 --- a/srs-anywhere-network.js +++ b/srs-anywhere-network.js @@ -50,7 +50,7 @@ window.addEventListener("load", () => { }); const downloadJSONOld = downloadJSON; -function downloadJSON() { +function downloadJSON(obj) { const password = document.getElementById('network-password').value; const xhr = new XMLHttpRequest(); xhr.open('POST', '/cgi-bin/deck.py', true); @@ -63,4 +63,32 @@ function downloadJSON() { } }; xhr.send(JSON.stringify(window.allCards, null, 2)); + + const inputButton = document.getElementById('cards-input'); + + const saveButton = document.createElement('button'); + saveButton.textContent = "Save JSON"; + + saveButton.addEventListener('click', () => { + // We move the logic inside the click listener so that it + // always saves the CURRENT state of 'obj' if it has changed. + const jsonString = JSON.stringify(obj, null, 2); + const blob = new Blob([jsonString], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + + // Create a "ghost" anchor to trigger the download + const a = document.createElement('a'); + a.href = url; + a.download = 'data.json'; + + // Append to body, click it, and remove it immediately + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + + // Clean up the URL object to free up memory + URL.revokeObjectURL(url); + }); + + inputButton.parentNode.insertBefore(saveButton, inputButton); } |