Add error page + Fix special chars bug

This commit is contained in:
Danny Spina 2023-06-22 16:38:38 +02:00
parent 7051221b1b
commit eefda848a7
3 changed files with 31 additions and 4 deletions

2
dist/index.html vendored
View File

@ -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);
});
</script>
</body>

View File

@ -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(`
<div style="display: flex; align-items: center; flex-direction: column; justify-content: center; font-family: sans-serif; width: 100%; height: 100%">
<h1>Blaze could not load the page :(</h1>
<p>Reason: <code>${xhr.status} ${xhr.statusText}</code></p>
<br />
<br />
<p>
If you want (it would be great!) you can report this problem, writing the requested URL and the reason,
at <a href="mailto:support.blaze@dannyspina.com">support.blaze@dannyspina.com</a>
</p>
<br />
<a href="#" role="button" onclick="history.back()">Go back</a>
</div>
`);
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";

View File

@ -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);
});
}