aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze2026-10-16 13:34:13 -0400
committerJakob L. Kreuze2026-10-16 13:34:29 -0400
commite552c980a7629c819a77af5c984912fd4aa40ea6 (patch)
treec7d69d4d6ef22260f885ca4ebbf50bcdc31e5105
parent5752078582767fbf9619bf3e886c2effab6de9f4 (diff)
Fall back to downloading the JSON file if network saves fail
-rw-r--r--srs-anywhere-network.js53
1 files changed, 29 insertions, 24 deletions
diff --git a/srs-anywhere-network.js b/srs-anywhere-network.js
index 8d972cc..40291a8 100644
--- a/srs-anywhere-network.js
+++ b/srs-anywhere-network.js
@@ -71,33 +71,38 @@ window.addEventListener("load", () => {
const downloadJSONOld = downloadJSON;
function downloadJSON(obj) {
- const password = document.getElementById('network-password').value;
- const xhr = new XMLHttpRequest();
- xhr.open('POST', '/cgi-bin/deck.py', true);
- xhr.setRequestHeader('PASSWORD', password);
- xhr.onreadystatechange = function () {
- if (xhr.readyState === XMLHttpRequest.DONE) {
- if (xhr.status < 200 || xhr.status >= 300) {
- reportException(xhr.statusText);
+ try {
+ const password = document.getElementById('network-password').value;
+ const xhr = new XMLHttpRequest();
+ xhr.open('POST', '/cgi-bin/deck.py', true);
+ xhr.setRequestHeader('PASSWORD', password);
+ xhr.onreadystatechange = function () {
+ if (xhr.readyState === XMLHttpRequest.DONE) {
+ if (xhr.status < 200 || xhr.status >= 300) {
+ reportException(xhr.statusText);
- const jsonString = JSON.stringify(obj, null, 2);
- const blob = new Blob([jsonString], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
+ 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';
+ // 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);
+ // 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);
+ // Clean up the URL object to free up memory
+ URL.revokeObjectURL(url);
+ }
}
- }
- };
- xhr.send(JSON.stringify(window.allCards, null, 2));
+ };
+ xhr.send(JSON.stringify(window.allCards, null, 2));
+ } catch (e) {
+ reportException(e);
+ downloadJSONOld(obj);
+ }
}

© 2015 - 2026 Jakob L. Kreuze