44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
window.addEventListener("load", () => {
|
|
const comments = document.querySelector(".comments");
|
|
const id = new URLSearchParams(document.location.search).get("v");
|
|
|
|
function showMore(e) {
|
|
let a = e.target.cloneNode(true);
|
|
a.classList.remove("show-more");
|
|
a.classList.add("comment-thread");
|
|
e.target.replaceWith(a);
|
|
fetchComments(a, a.dataset.uwu);
|
|
}
|
|
|
|
function fetchComments(div, cont) {
|
|
div.innerText = "Loading...";
|
|
if(!cont) {
|
|
url = "/comments.shs?v=" + id;
|
|
} else {
|
|
url = "/comments.shs?cont=" + cont;
|
|
}
|
|
fetch(url).then(
|
|
res => {
|
|
if (res.status !== 200) {
|
|
throw new Error('HTTP Error ' + res.status);
|
|
}
|
|
return res.text();
|
|
}
|
|
).then(
|
|
res => {
|
|
div.innerHTML = res;
|
|
if(!cont) {
|
|
let show_more = document.querySelectorAll(".show-more");
|
|
show_more.forEach((elem) => {
|
|
elem.addEventListener("click", (e) => showMore(e));
|
|
});
|
|
}
|
|
}
|
|
).catch(
|
|
err => div.innerText = 'Error during fetching comments: ' + err.message
|
|
)
|
|
}
|
|
|
|
fetchComments(comments);
|
|
})
|