21 lines
858 B
JavaScript
21 lines
858 B
JavaScript
window.onload = async () => {
|
|
let id = (await (await fetch("/api/captcha", {method: "POST"})).json()).id
|
|
console.log(id);
|
|
fetch(`/api/captcha/${id}`).then(response => response.blob())
|
|
.then(blob => {
|
|
const url = URL.createObjectURL(blob);
|
|
document.getElementById("captcha_image").src = url;
|
|
}
|
|
);
|
|
const form = document.getElementById("captchaForm");
|
|
const inputField = document.getElementById("captcha");
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const response = await fetch(`/api/captcha/${id}`, {method: "PATCH",headers: {'Content-Type': 'application/json'}, body: JSON.stringify({"solution": inputField.value})});
|
|
if (response.status == 200) {
|
|
inputField.value = "";
|
|
window.location.reload();
|
|
};
|
|
})
|
|
}; |