async function remove_post_handler(event) {
const post = event.currentTarget.closest('.post');
- const username = post.querySelector(".author .username,.author .username-coloured").text;
+ const usernameElem = post.querySelector(".author .username,.author .username-coloured");
+ const username = usernameElem.textContent;
const thread_title = document.querySelector('.topic-title a').text;
const content = ellipsify(post.querySelector(".content").innerText, 250);
/* Prompting for a separate ban reason in case there is something more
* specific to note here.
*/
- const banReason = window.prompt(`Benutzer „${username}“ sperren?\n\nGrund:`, "Spam");
+ const userStillExists = usernameElem.nodeName === "A";
+ const banReason = userStillExists &&
+ window.prompt(`Benutzer „${username}“ sperren?\n\nGrund:`, "Spam");
const shouldCloseReport = isPostReported(post) && window.confirm("Meldung zum Beitrag schließen?");
/* Initially, I wanted to use Promise.allSettled() below to trigger and wait
errors.push(err);
}
- if (banReason !== null) {
+ if (banReason) {
try {
await banUser(username, banReason);
} catch (err) {