]> git.aero2k.de Git - dfde/quickmods.git/commitdiff
Make all URLs absolute for fetching
authorJTH <JTH@debianforum.de>
Fri, 16 Sep 2022 16:15:16 +0000 (18:15 +0200)
committerThorsten <mail@aero2k.de>
Fri, 16 Sep 2022 17:21:48 +0000 (19:21 +0200)
quickmod.user.js

index 2b30f7d389226bc0fb303562939455f4bdb7492b..f552029d414988d5ee0cad3db4e87b41250df18e 100644 (file)
@@ -14,7 +14,7 @@ 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");
+    let resp = await fetch(toAbsoluteURL("./mcp.php?i=ban&mode=user"));
     if (!resp.ok) {
         throw "Konnte Formular zum Sperren von Benutzern nicht laden.";
     }
@@ -44,7 +44,7 @@ async function banUser(username, reason) {
 async function closeReport(post) {
     const reportLink = post.querySelector(".post-notice.reported a");
 
-    let resp = await fetch(reportLink.href);
+    let resp = await fetch(toAbsoluteURL(reportLink.href));
     if (!resp.ok) {
         throw "Konnte Meldung nicht öffnen.";
     }
@@ -106,7 +106,7 @@ function postForm(form, formData, submitName) {
     /* Have to use explicit getAttribute() below since there is an input with
      * name="action" which would be accessed with `form.action` :-/
      */
-    return fetch(form.getAttribute("action"),
+    return fetch(toAbsoluteURL(form.getAttribute("action")),
         { body: new URLSearchParams(formData), method: "POST" });
 }
 
@@ -178,7 +178,7 @@ async function remove_post_handler(event) {
 
 async function send_mcp_request_archival(post, reason) {
     const splitLink = document.querySelector("#quickmod .dropdown-contents a[href*='action=split']");
-    let resp = await fetch(splitLink.href);
+    let resp = await fetch(toAbsoluteURL(splitLink.href));
     if (!resp.ok) {
         throw "Konnte Formular zum Aufteilen des Themas nicht laden.";
     }
@@ -215,6 +215,10 @@ async function send_mcp_request_archival(post, reason) {
     }
 }
 
+function toAbsoluteURL(relativeOrAbsoluteURL) {
+    return new URL(relativeOrAbsoluteURL, window.location);
+}
+
 function updatePageAfterSplit(post) {
     if (document.querySelectorAll(".post").length > 1) {
         post.parentNode.removeChild(post);