-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
31 lines (28 loc) · 799 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/sw.js", { type: "module" })
.catch(console.error);
}
window.addEventListener("submit", async (event) => {
event.preventDefault();
const data = new FormData(event.target);
const url = data.get("url");
data.delete("url");
const body = JSON.stringify(Object.fromEntries(data.entries()));
try {
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Many-Request": true,
},
mode: "cors",
body,
});
const json = await res.json();
const el = document.getElementById("response");
el.innerHTML = JSON.stringify(json, null, 2);
} catch (error) {
console.log("[MAIN] Fetch error:", error);
}
});