From 82a7fb96e6aeb191c64d98f10b422be0441af218 Mon Sep 17 00:00:00 2001 From: Artemy Date: Fri, 18 Aug 2023 11:38:30 +0300 Subject: [PATCH] fix: google name parsing --- src/handlers/google.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/handlers/google.ts b/src/handlers/google.ts index 8501652..9caccf8 100644 --- a/src/handlers/google.ts +++ b/src/handlers/google.ts @@ -8,13 +8,13 @@ export default async function google( const googleAnchors = [ ...window.document.querySelectorAll("a[jsname=ACyKwe]"), ] as HTMLAnchorElement[]; - const googleNames = [...window.document.querySelectorAll(".VuuXrf")]; const results = googleAnchors - .map((a: HTMLAnchorElement, i: number): GoogleProps => { + .map((a: HTMLAnchorElement): GoogleProps => { + const parsedHref = new URL(new URL(a.href).searchParams.get("url")!); return { href: a.href!, - siteName: googleNames[i].textContent!, + siteName: parsedHref.hostname, heading: a.childNodes[1]?.textContent, }; }) @@ -26,12 +26,6 @@ export default async function google( ); } - if (!googleNames) { - throw new EngineParseError( - "Failed to find names in search result [google]" - ); - } - const convertToFormat = (result: GoogleProps, isHtml: boolean) => { return isHtml ? `

${result.siteName} - ${result.heading}

`