mirror of
https://github.com/cupcakearmy/blaze.git
synced 2025-01-10 01:16:32 +00:00
26 lines
764 B
TypeScript
26 lines
764 B
TypeScript
export const blazeUrl = process.env.DEV_MODE
|
|
? "http://localhost:8888"
|
|
: "https://blaze.cyclic.app";
|
|
|
|
export function injectBlazeToPageLinks(blazeUrl: string, currentUrl: string) {
|
|
const url = new URL(currentUrl);
|
|
const re = new RegExp("^(http|https)://", "i");
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
const links = document.querySelectorAll("a");
|
|
links.forEach((link) => {
|
|
let originalHref = link.getAttribute("href");
|
|
|
|
if (!originalHref) {
|
|
return;
|
|
}
|
|
|
|
const isAbsoluteLink = re.test(originalHref);
|
|
if (!isAbsoluteLink) {
|
|
originalHref = `${url.protocol}//${url.hostname}${originalHref}`;
|
|
}
|
|
|
|
link.setAttribute("href", `${blazeUrl}/blazed?url=${originalHref}`);
|
|
});
|
|
});
|
|
}
|