diff --git a/dist/index.html b/dist/index.html index f8a5bf7..b4bf61a 100644 --- a/dist/index.html +++ b/dist/index.html @@ -60,7 +60,7 @@ t = document.querySelector("button"), c = document.querySelector("input"); t.addEventListener("click", () => { - location.href = e + "?q=" + encodeURI(c.value); + location.href = e + "?q=" + encodeURIComponent(c.value); }); diff --git a/index.ts b/index.ts index 2de9df0..91f1bd4 100644 --- a/index.ts +++ b/index.ts @@ -50,7 +50,12 @@ app.get("/", async (req, res) => { try { const xhr = new XMLHttpRequest(); - xhr.open("GET", `${searchEngine}?q=${query}&safesearch=moderate`, true); + const formattedQuery = encodeURIComponent(query); + xhr.open( + "GET", + `${searchEngine}?q=${formattedQuery}&safesearch=moderate`, + true + ); xhr.setRequestHeader("Accept", "*/*"); xhr.setRequestHeader("X-Subscription-Token", key); @@ -139,6 +144,20 @@ app.get("/blazed", async (req, res) => { if (xhr.status !== 200) { console.error("XHR request failed:", xhr.status, xhr.statusText); + res.send(` +
+

Blaze could not load the page :(

+

Reason: ${xhr.status} ${xhr.statusText}

+
+
+

+ If you want (it would be great!) you can report this problem, writing the requested URL and the reason, + at support.blaze@dannyspina.com +

+
+ Go back +
+ `); return; } @@ -153,13 +172,21 @@ app.get("/blazed", async (req, res) => { }); document.querySelectorAll("style").forEach((s) => { - s.remove; + s.remove(); }); document.querySelectorAll("script").forEach((s) => { s.remove(); }); + document.querySelectorAll("img").forEach((i) => { + i.remove(); + }); + + document.querySelectorAll("iframe").forEach((f) => { + f.remove(); + }); + const blazeDisclaimer = document.createElement("div"); blazeDisclaimer.style.width = "100dvw"; blazeDisclaimer.style.border = "1px solid red"; diff --git a/utils.ts b/utils.ts index 7dcbb99..a7ea9e4 100644 --- a/utils.ts +++ b/utils.ts @@ -28,6 +28,6 @@ export function blazeFunctionality(blazeUrl: string) { const t = document.querySelector("button"), c = document.querySelector("input"); t!.addEventListener("click", () => { - location.href = blazeUrl + "?q=" + encodeURI(c.value); + location.href = blazeUrl + "?q=" + encodeURIComponent(c!.value); }); }