+async function banUser(username, reason) {
+ /* The URL to the ban form does not need any IDs or hidden inputs. We
+ * hardcode it here.
+ */
+ let resp = await fetch("./mcp.php?i=ban&mode=user");
+ if (!resp.ok) {
+ throw "Konnte Formular zum Sperren von Benutzern nicht laden.";
+ }
+
+ let form, formData;
+ try {
+ [form, formData] = await openForm(resp, "form#mcp_ban");
+ } catch {
+ throw "Konnte Formular zum Sperren von Benutzern nicht öffnen.";
+ }
+
+ formData.set("ban", username);
+ formData.set("banreason", reason);
+ //formData.set("bangivereason", reason);
+ resp = await postForm(form, formData, "bansubmit");
+ if (!resp.ok) {
+ throw "Konnte Sperrung des Benutzers nicht anfragen.";
+ }
+
+ try {
+ await confirmAction(resp);
+ } catch (err) {
+ throw `Konnte Sperrung des Benutzers nicht bestätigen: ${err}`;
+ }
+}
+
+async function closeReport(post) {
+ const reportLink = post.querySelector(".post-notice.reported a");
+
+ let resp = await fetch(reportLink.href);
+ if (!resp.ok) {
+ throw "Konnte Meldung nicht öffnen.";
+ }
+
+ let form, formData;
+ try {
+ [form, formData] = await openForm(resp, "form#mcp_report");
+ } catch {
+ throw "Konnte Formular zum Schließen der Meldung nicht öffnen.";
+ }
+
+ resp = await postForm(form, formData, "action[close]");
+ if (!resp.ok) {
+ throw "Konnte Schließen der Meldung nicht anfragen.";
+ }
+
+ try {
+ await confirmAction(resp);
+ } catch (err) {
+ throw `Konnte Schließen der Meldung nicht bestätigen: ${err}`;
+ }
+}
+
+async function confirmAction(response) {
+ const [form, formData] = await openForm(response, "form#confirm");
+
+ /* Have to use explicit getAttribute() below since there is an input with
+ * name="action" which would be accessed with `form.action` :-/
+ */
+ const resp = await postForm(form, formData, "confirm");
+ if (!resp.ok) {
+ throw `${resp.url}: ${resp.status}`;
+ }
+ return await resp.text();
+}