Niansuh's picture
Create static/admin.js
3d8c947 verified
raw
history blame
743 Bytes
document.getElementById("addCreditForm").addEventListener("submit", async function(e) {
e.preventDefault();
const username = document.getElementById("username").value;
const credits = parseInt(document.getElementById("credits").value, 10);
// Prompt for the admin API key
const apiKey = prompt("Enter your admin API key:");
const response = await fetch("/admin/add_credit", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": apiKey
},
body: JSON.stringify({ username, credits })
});
const result = await response.json();
document.getElementById("result").innerText = JSON.stringify(result, null, 2);
});