From c841bb43bfadfcf5e8dcb731ee38e3392340a6cb Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Fri, 5 Dec 2025 14:59:09 -0500 Subject: Add loading from network --- Makefile | 8 +++++--- srs-anywhere-network.js | 41 +++++++++++++++++++++++++++++++++++++++++ srs-anywhere.html.tpl | 7 ++++++- 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 srs-anywhere-network.js diff --git a/Makefile b/Makefile index a4b9412..b02bd6b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ all: srs-anywhere.html deck-editor.html -srs-anywhere.html: srs-anywhere.html.tpl style.css srs-anywhere.js - sed '/@@JS@@/r srs-anywhere.js' < srs-anywhere.html.tpl | \ - sed '/@@JS@@/d' | \ +srs-anywhere.html: srs-anywhere.html.tpl style.css srs-anywhere.js srs-anywhere-network.js + sed '/@@JS1@@/r srs-anywhere.js' < srs-anywhere.html.tpl | \ + sed '/@@JS1@@/d' | \ + sed '/@@JS2@@/r srs-anywhere-network.js' | \ + sed '/@@JS2@@/d' | \ sed '/@@CSS@@/r style.css' | \ sed '/@@CSS@@/d' > srs-anywhere.html diff --git a/srs-anywhere-network.js b/srs-anywhere-network.js new file mode 100644 index 0000000..4d8e187 --- /dev/null +++ b/srs-anywhere-network.js @@ -0,0 +1,41 @@ +/* Copyright © 2025 Jakob L. Kreuze + + This file is part of SRS Anywhere. + + SRS Anywhere is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + SRS Anywhere is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public + License along with SRS Anywhere. If not, see . */ + +window.addEventListener("load", () => { + const btn = document.getElementById('open-network'); + const password = document.getElementById('network-password').value; + if (!btn) { + console.warn('Button with id="open-network" not found.'); + return; + } + + btn.addEventListener('click', function () { + const xhr = new XMLHttpRequest(); + xhr.open('GET', '/cgi-bin/deck.py', true); + xhr.setRequestHeader('PASSWORD', password); + xhr.onreadystatechange = function () { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status >= 200 && xhr.status < 300) { + loadCards(JSON.parse(xhr.responseText)); + } else { + reportException(xhr.statusText); + } + } + }; + xhr.send(); + }); +}); diff --git a/srs-anywhere.html.tpl b/srs-anywhere.html.tpl index cf3010f..5d5c234 100644 --- a/srs-anywhere.html.tpl +++ b/srs-anywhere.html.tpl @@ -19,6 +19,8 @@ No cards loaded!
+ +

@@ -76,7 +78,10 @@ + -- cgit v1.3