This repository has been archived on 2024-10-20. You can view files and clone it, but cannot push or open issues or pull requests.
burgercat/static/js/main.js

61 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-07-08 17:00:32 +01:00
const posts = document.getElementsByClassName("post")
for (let i = 0; i < posts.length; i++) {
let post = posts[i]
let commentButton = post.children["commentButton"]
let commentId = post.children["commentId"]
2023-07-08 18:04:16 +01:00
let commentBurgerDiv = post.children["commentBurgerDiv"]
let usernameElement = post.children["usernameElement"]
2023-07-08 17:00:32 +01:00
let commentDiv = post.children["commentDiv"]
2023-07-10 17:53:11 +01:00
let removeButton = post.children["removeButton"]
2023-07-08 17:00:32 +01:00
let commentBox = commentDiv.children["commentBox"]
let commentSave = commentDiv.children["commentDivSave"]
let commentCancel = commentDiv.children["commentDivCancel"]
commentButton.addEventListener("click", (e) => {
commentDiv.classList.remove("hidden")
commentBox.value = ""
});
commentCancel.addEventListener("click", (e) => {
commentDiv.classList.add("hidden")
});
commentSave.addEventListener("click", (e) => {
console.log(commentId.innerHTML)
title = String(commentBox.value)
id = String(commentId.innerHTML)
2023-07-09 01:16:04 +01:00
commentDiv.classList.add("hidden")
commentBurgerDiv.classList.remove("hidden")
2023-07-08 18:04:16 +01:00
2023-07-09 01:16:04 +01:00
let para = document.createElement("p");
const node = document.createTextNode(usernameElement.innerHTML + ": " + title);
para.appendChild(node)
commentBurgerDiv.append(para)
2023-07-08 18:04:16 +01:00
2023-07-08 23:44:53 +01:00
fetch("/api/comment", {
2023-07-08 17:00:32 +01:00
method: "POST",
body: JSON.stringify({
id: id,
title: title,
}),
headers: {
"Content-Type": "application/json"
}
})
});
2023-07-10 17:53:11 +01:00
removeButton.addEventListener("click", (e) => {
console.log("fart")
post.classList.add("hidden")
id = String(commentId.innerHTML)
fetch("/api/delete", {
method: "POST",
body: JSON.stringify({
id: id
}),
headers: {
"Content-Type": "application/json"
}
})
});
2023-07-08 17:00:32 +01:00
}