blob: 193cfd6561231a4bdf6f8800e076ff864d9dafce (
plain) (
blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<!DOCTYPE html>
<html>
<head>
<title>Add Steam Game</title>
</head>
<body>
<h1>Add Steam Game</h1>
<form id="addForm">
<div>
<label>Steam App ID:</label><br>
<input type="number" id="steam_id" required>
</div>
<br>
<div>
<label>Password:</label><br>
<input type="password" id="password" required>
</div>
<br>
<button type="submit">Add Game</button>
</form>
<pre id="result"></pre>
<script>
const form = document.getElementById("addForm");
const passwordInput = document.getElementById("password");
const result = document.getElementById("result");
// Load saved password from localStorage
const savedPassword = localStorage.getItem("addFormPassword");
if (savedPassword) {
passwordInput.value = savedPassword;
}
// Save password to localStorage as user types
passwordInput.addEventListener("input", () => {
localStorage.setItem("addFormPassword", passwordInput.value);
});
form.addEventListener("submit", async (e) => {
e.preventDefault();
const steamId = document.getElementById("steam_id").value;
const password = passwordInput.value; // Use the input element's current value
// Clear previous results
result.textContent = "";
try {
const res = await fetch(`/api/steam/${steamId}`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ password })
});
const data = await res.json();
if (!res.ok) { // Check if response status is not OK (e.g., 401, 500)
throw new Error(data.error || `HTTP error! status: ${res.status}`);
}
// Success case
result.textContent = `Success! Game added:\n${JSON.stringify(data, null, 2)}`;
// Optionally clear form fields on success
// document.getElementById("steam_id").value = "";
// passwordInput.value = ""; // Keep password if user wants to add more
// localStorage.removeItem("addFormPassword"); // Or remove password on success if desired
} catch (error) {
// Error case
result.textContent = `Error: ${error.message}`;
console.error("Error adding game:", error);
}
});
</script>
</body>
</html>
|