CensoredManager/assets/js/delete.js

28 lines
1.1 KiB
JavaScript
Raw Normal View History

const token = docCookies.getItem("token");
const notificationElement = document.getElementById("notification");
const balanceElement = document.getElementById("balance");
window.addEventListener("load", async function () {
balanceElement.innerText = await getBalance(token);
});
document.getElementById("delete-form").addEventListener("submit", async (e) => {
e.preventDefault();
const id = document.getElementById("id").value;
const infoResult = await chequeInfo(id);
if (infoResult !== undefined) {
const coinsLeft = infoResult['amount'] * infoResult['count'];
const deleteResult = await deleteCheque(token, id);
if (deleteResult !== undefined) {
notificationElement.innerText = `+${coinsLeft} coins`;
notificationElement.style.color = "green";
balanceElement.innerText = deleteResult;
} else {
notificationElement.innerText = "You do not own this cheque.";
notificationElement.style.color = "red";
}
} else {
notificationElement.innerText = "Incorrect ID!";
notificationElement.style.color = "red";
}
});