From: JTH Date: Fri, 16 Sep 2022 09:15:06 +0000 (+0200) Subject: Only suggest user ban if user not already deleted X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=94478f7f75311e21ab371a39fd0f060f0efe10c5;p=dfde%2Fquickmods.git Only suggest user ban if user not already deleted --- diff --git a/quickmod.user.js b/quickmod.user.js index 8905d6a..a30d075 100644 --- a/quickmod.user.js +++ b/quickmod.user.js @@ -112,7 +112,8 @@ function postForm(form, formData, submitName) { 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); @@ -125,7 +126,9 @@ async function remove_post_handler(event) { /* 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 @@ -145,7 +148,7 @@ async function remove_post_handler(event) { errors.push(err); } - if (banReason !== null) { + if (banReason) { try { await banUser(username, banReason); } catch (err) {