mirror of
https://github.com/cupcakearmy/blaze.git
synced 2024-12-22 08:16:26 +00:00
Add error page + Fix special chars bug
This commit is contained in:
parent
7051221b1b
commit
eefda848a7
2
dist/index.html
vendored
2
dist/index.html
vendored
@ -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>
|
||||
|
31
index.ts
31
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(`
|
||||
<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";
|
||||
|
2
utils.ts
2
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);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user