Files
chookchat/client/script.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2026-07-20 20:11:06 +10:00
async function like(id) {
2026-07-21 12:06:46 +10:00
const formData = new FormData();
formData.append('post', id);
const result = await fetch('/like', {
method: 'POST',
body: formData
});
if (result.status === 401) {
alert("you need to login before you like a post");
return;
}
if (result.status < 200 || result.status >= 400) {
alert("your post didnt get the like because the server thought your opinion was invalid");
return;
}
}
async function register() {
2026-07-20 19:02:04 +10:00
const usernameBox = document.getElementById('username');
const passwordBox = document.getElementById('password');
const formData = new FormData();
formData.append('username', usernameBox.value);
formData.append('password', passwordBox.value);
2026-07-21 12:06:46 +10:00
const result = await fetch('/register', {
2026-07-20 20:11:06 +10:00
method: 'POST',
body: formData
2026-07-20 19:02:04 +10:00
});
2026-07-20 20:11:06 +10:00
if (result.status < 200 || result.status >= 400) {
2026-07-21 12:06:46 +10:00
alert("fard");
return;
2026-07-20 20:11:06 +10:00
}
2026-07-21 12:06:46 +10:00
window.location.href = "/";
}
async function login() {
const usernameBox = document.getElementById('username');
const passwordBox = document.getElementById('password');
const formData = new FormData();
formData.append('username', usernameBox.value);
formData.append('password', passwordBox.value);
console.log(formData);
const result = await fetch('/login', {
method: 'POST',
body: formData
});
if (result.status < 200 || result.status >= 400) {
alert("for some reason the server hates you and didn't let you log into your account");
console.log(result.status);
console.log(result.content);
return;
}
window.location.href = "/";
2026-07-20 19:02:04 +10:00
}