diff --git a/dist/styles/serp.css b/dist/styles/serp.css new file mode 100644 index 0000000..e69de29 diff --git a/index.ts b/index.ts index 9823112..f2a8206 100644 --- a/index.ts +++ b/index.ts @@ -12,6 +12,7 @@ import { minify } from "html-minifier"; import { blazeFunctionality, blazeUrl, + highlightBlazedLinks, injectBlazeToPageLinks, } from "./utils.js"; import etag from "etag"; @@ -86,9 +87,9 @@ app.get("/", async (req, res) => { const results = data.web.results.map( (result: any) => `
- -

${result.title}

-
+

+ ${result.title} +

${result.meta_url.hostname}

${result.description}

@@ -122,7 +123,12 @@ app.get("/", async (req, res) => { ${results.join("")} @@ -261,6 +267,10 @@ app.get("/blazed", async (req, res) => { const url = "${blazeUrl}" const currentUrl = "${req.query.url}" injectBlazeToPageLinks(url, currentUrl) + + ${highlightBlazedLinks} + const links = document.querySelectorAll('a') + highlightBlazedLinks(links) `; diff --git a/utils.ts b/utils.ts index a7ea9e4..68a5006 100644 --- a/utils.ts +++ b/utils.ts @@ -31,3 +31,24 @@ export function blazeFunctionality(blazeUrl: string) { location.href = blazeUrl + "?q=" + encodeURIComponent(c!.value); }); } + +export function highlightBlazedLinks(links: HTMLLinkElement[]) { + links.forEach((link) => { + if ( + !link.href || + link.href === "http://localhost:8888/" || + link.href === "https://blaze.cyclic.app" + ) { + return; + } + + const url = new URL(link.href); + caches.open("blaze").then((cache) => { + cache.match(url.href).then((response) => { + if (response) { + link.innerHTML = `${link.textContent} ⚡`; + } + }); + }); + }); +}