I was greatly overcomplicating the custom favicon system LOL
This commit is contained in:
parent
9bc3473bc7
commit
bea33a22c6
2 changed files with 42 additions and 88 deletions
41
index.js
41
index.js
|
|
@ -81,42 +81,13 @@ app.use((req, res, next) => {
|
||||||
});
|
});
|
||||||
app.use("/custom-favicon", async (req, res) => {
|
app.use("/custom-favicon", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { url, contentType } = req.query;
|
const { url } = req.query;
|
||||||
const urlExt = url.split(".").pop();
|
const response = await fetch(`https://www.google.com/s2/favicons?domain=${url}&sz=128`);
|
||||||
const response = await fetch(url);
|
const buffer = new Buffer.from(await response.arrayBuffer());
|
||||||
const arrayBuffer = await response.arrayBuffer();
|
res.set("Content-Type", "image/png");
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
|
||||||
console.log(contentType);
|
|
||||||
if (contentType || !contentType == "") {
|
|
||||||
res.setHeader("Content-Type", contentType);
|
|
||||||
} else {
|
|
||||||
switch (urlExt) {
|
|
||||||
case "png":
|
|
||||||
res.setHeader("Content-Type", "image/png");
|
|
||||||
break;
|
|
||||||
case "jpg":
|
|
||||||
res.setHeader("Content-Type", "image/jpeg");
|
|
||||||
break;
|
|
||||||
case "jpeg":
|
|
||||||
res.setHeader("Content-Type", "image/jpeg");
|
|
||||||
break;
|
|
||||||
case "gif":
|
|
||||||
res.setHeader("Content-Type", "image/gif");
|
|
||||||
break;
|
|
||||||
case "svg":
|
|
||||||
res.setHeader("Content-Type", "image/svg+xml");
|
|
||||||
break;
|
|
||||||
case "ico":
|
|
||||||
res.setHeader("Content-Type", "image/x-icon");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
res.setHeader("Content-Type", "image/png");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res.send(buffer);
|
res.send(buffer);
|
||||||
} catch (err) {
|
} catch {
|
||||||
res.send(`Error: ${err}`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
app.use("/", express.static("dist/client/"));
|
app.use("/", express.static("dist/client/"));
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUVProxyURL(frame: HTMLIFrameElement) {
|
||||||
|
return window.__uv$config.decodeUrl(
|
||||||
|
frame.contentWindow!.location.href.split("/service/")[1]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
async function loadContent() {
|
async function loadContent() {
|
||||||
await initTransport();
|
await initTransport();
|
||||||
// The setTimeout is because service workers are a little silly and can take a while longer to register despite .then being called, which causes a bug on the first load.
|
// The setTimeout is because service workers are a little silly and can take a while longer to register despite .then being called, which causes a bug on the first load.
|
||||||
|
|
@ -129,29 +135,29 @@
|
||||||
iframe.classList.add("active");
|
iframe.classList.add("active");
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadExtensionScripts() {
|
// function loadExtensionScripts() {
|
||||||
try {
|
// try {
|
||||||
let db = indexedDB.open("AluDB", 1);
|
// let db = indexedDB.open("AluDB", 1);
|
||||||
db.onsuccess = () => {
|
// db.onsuccess = () => {
|
||||||
let transaction = db.result.transaction("InstalledExtensions", "readonly");
|
// let transaction = db.result.transaction("InstalledExtensions", "readonly");
|
||||||
let store = transaction.objectStore("InstalledExtensions");
|
// let store = transaction.objectStore("InstalledExtensions");
|
||||||
let request = store.getAll();
|
// let request = store.getAll();
|
||||||
request.onsuccess = () => {
|
// request.onsuccess = () => {
|
||||||
let extensions = request.result;
|
// let extensions = request.result;
|
||||||
extensions.forEach((extension: any) => {
|
// extensions.forEach((extension: any) => {
|
||||||
// Eval the extension script inside of the iframe
|
// // Eval the extension script inside of the iframe
|
||||||
if (extension.serviceWorkerExtension) return;
|
// if (extension.serviceWorkerExtension) return;
|
||||||
if (iframe.contentWindow) {
|
// if (iframe.contentWindow) {
|
||||||
console.log(`Evaluating extension "${extension.title}" inside of the iframe.`);
|
// console.log(`Evaluating extension "${extension.title}" inside of the iframe.`);
|
||||||
(iframe.contentWindow as any).eval(atob(extension.script));
|
// (iframe.contentWindow as any).eval(atob(extension.script));
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
};
|
// };
|
||||||
} catch (err) {
|
// } catch (err) {
|
||||||
console.error(`Failed load extension scripts: ${err}`);
|
// console.error(`Failed load extension scripts: ${err}`);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function iframeLoad(
|
function iframeLoad(
|
||||||
iframe: HTMLIFrameElement,
|
iframe: HTMLIFrameElement,
|
||||||
|
|
@ -204,9 +210,7 @@
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
navigator.clipboard.writeText(
|
navigator.clipboard.writeText(
|
||||||
window.__uv$config.decodeUrl(
|
getUVProxyURL(proxyFrame)
|
||||||
proxyFrame.contentWindow!.location.href.split("/service/")[1]
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
new Notyf({
|
new Notyf({
|
||||||
|
|
@ -303,34 +307,13 @@
|
||||||
let favicon =
|
let favicon =
|
||||||
(iframe.contentDocument.querySelector("link[rel='icon']") as HTMLLinkElement) ||
|
(iframe.contentDocument.querySelector("link[rel='icon']") as HTMLLinkElement) ||
|
||||||
(iframe.contentDocument.querySelector("link[rel*='icon']") as HTMLLinkElement);
|
(iframe.contentDocument.querySelector("link[rel*='icon']") as HTMLLinkElement);
|
||||||
if (favicon && favicon.href) {
|
if (favicon && favicon.href.includes("data:image")) {
|
||||||
let encodedHREF = encodeURIComponent(favicon.href);
|
proxiedFavicon.src = favicon.href;
|
||||||
if (favicon.href.includes("data:image")) {
|
return;
|
||||||
proxiedFavicon.src = favicon.href;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
proxiedFavicon.src ==
|
|
||||||
`${window.location.origin}/custom-favicon?url=${encodedHREF}&contentType=${favicon.type ? encodeURIComponent(favicon.type) : ""}`
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (favicon) {
|
let UVURL = getUVProxyURL(iframe);
|
||||||
let encodedHREF = encodeURIComponent(favicon.href);
|
if (proxiedFavicon.src == `${window.location.origin}/custom-favicon?url=${UVURL}`) return;
|
||||||
if (favicon.href.includes("data:image")) {
|
proxiedFavicon.src = `/custom-favicon?url=${UVURL}`;
|
||||||
proxiedFavicon.src = favicon.href;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
proxiedFavicon.src = `/custom-favicon?url=${encodedHREF}&contentType=${favicon.type ? encodeURIComponent(favicon.type) : ""}`;
|
|
||||||
proxiedFavicon.addEventListener("error", () => {
|
|
||||||
proxiedFavicon.src = "/favicon.ico";
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (proxiedFavicon.src != window.location.origin + "/favicon.ico") {
|
|
||||||
proxiedFavicon.src = "/favicon.ico";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue