diff options
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | srs-anywhere-network.js | 41 | ||||
| -rw-r--r-- | srs-anywhere.html.tpl | 7 |
3 files changed, 52 insertions, 4 deletions
@@ -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 <https://www.gnu.org/licenses/>. */ + +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! </div> <hr> + <input type="text" id="network-password" /> <button id="open-network">Go!</button> + <br> <input type="file" id="cards-input" accept=".json" /> <button id="open-modal">?</button> <br /> @@ -76,7 +78,10 @@ </div> <script> - @@JS@@ + @@JS1@@ + </script> + <script> + @@JS2@@ </script> <script src="srs-anywhere-custom-card-types.js"></script> </body> |