summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--srs-anywhere-network.js66
-rw-r--r--srs-anywhere.html.tpl7
3 files changed, 77 insertions, 4 deletions
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..3687402
--- /dev/null
+++ b/srs-anywhere-network.js
@@ -0,0 +1,66 @@
+/* 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 passwordField = document.getElementById('network-password');
+
+ const urlParams = new URLSearchParams(window.location.search);
+ let password = localStorage.getItem('password') || urlParams.get('password');
+ if (password) {
+ passwordField.value = password;
+ }
+
+ const btn = document.getElementById('open-network');
+ if (!btn) {
+ console.warn('Button with id="open-network" not found.');
+ return;
+ }
+
+ btn.addEventListener('click', function () {
+ const password = passwordField.value;
+ 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) {
+ localStorage.setItem('password', password);
+ loadCards(JSON.parse(xhr.responseText));
+ } else {
+ reportException(xhr.statusText);
+ }
+ }
+ };
+ xhr.send();
+ });
+});
+
+const downloadJSONOld = downloadJSON;
+function downloadJSON() {
+ 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);
+ }
+ }
+ };
+ xhr.send(JSON.stringify(window.allCards, null, 2));
+}
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>