From fb61b42c54cc56541b7c3e250b09fd2eef7b96eb Mon Sep 17 00:00:00 2001 From: JTH Date: Fri, 16 Sep 2022 18:15:16 +0200 Subject: [PATCH] Make all URLs absolute for fetching --- quickmod.user.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/quickmod.user.js b/quickmod.user.js index 2b30f7d..f552029 100644 --- a/quickmod.user.js +++ b/quickmod.user.js @@ -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); -- 2.39.2