summaryrefslogtreecommitdiff
path: root/srs-anywhere-network.js
blob: 4d8e187139d583bf18a3472732b4d63548a8cf17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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();
  });
});