mirror of
https://github.com/txtdot/txtdot
synced 2024-10-18 14:40:19 +03:00
feat: fix google parsing
there's no more navigation
This commit is contained in:
parent
92579334a0
commit
c6cef00f63
@ -3,17 +3,17 @@ import { IHandlerOutput } from "./handler.interface";
|
|||||||
import { EngineParseError } from "../errors/main";
|
import { EngineParseError } from "../errors/main";
|
||||||
|
|
||||||
export default async function google(
|
export default async function google(
|
||||||
input: HandlerInput,
|
input: HandlerInput
|
||||||
): Promise<IHandlerOutput> {
|
): Promise<IHandlerOutput> {
|
||||||
const window = input.parseDom().window;
|
const window = input.parseDom().window;
|
||||||
|
|
||||||
const googleAnchors = [
|
const googleAnchors = [
|
||||||
...window.document.querySelectorAll("a[jsname=ACyKwe]"),
|
...window.document.querySelectorAll("a[jsname=UWckNb]"),
|
||||||
] as HTMLAnchorElement[];
|
] as HTMLAnchorElement[];
|
||||||
|
|
||||||
if (!googleAnchors) {
|
if (!googleAnchors) {
|
||||||
throw new EngineParseError(
|
throw new EngineParseError(
|
||||||
"Failed to find anchors in search result [google]",
|
"Failed to find anchors in search result [google]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,31 +43,9 @@ export default async function google(
|
|||||||
});
|
});
|
||||||
|
|
||||||
const search = window.document.getElementById(
|
const search = window.document.getElementById(
|
||||||
"APjFqb",
|
"APjFqb"
|
||||||
) as HTMLTextAreaElement;
|
) as HTMLTextAreaElement;
|
||||||
|
|
||||||
const navLinks = [
|
|
||||||
...window.document.querySelectorAll(
|
|
||||||
"table[class=AaVjTc] > tbody > tr > td > a",
|
|
||||||
),
|
|
||||||
].map((l) => {
|
|
||||||
const link = l as HTMLAnchorElement;
|
|
||||||
return `<td><a href="${link.href}">${link.innerHTML}</a></td>`;
|
|
||||||
});
|
|
||||||
|
|
||||||
const currPage =
|
|
||||||
(window.document.querySelector(".YyVfkd") as HTMLTableCellElement)
|
|
||||||
?.cellIndex || 0;
|
|
||||||
|
|
||||||
const pageTd = `<td>${currPage}</td>`;
|
|
||||||
|
|
||||||
if (currPage === 1) navLinks.splice(currPage - 1, 0, pageTd);
|
|
||||||
else if (currPage !== 0) navLinks.splice(currPage, 0, pageTd);
|
|
||||||
|
|
||||||
const navigation = `<table>
|
|
||||||
<tbody><tr>${navLinks.join("")}</tr></tbody>
|
|
||||||
</table>`;
|
|
||||||
|
|
||||||
const searchForm = `
|
const searchForm = `
|
||||||
<form onsubmit="window.location.href = '/get?url=https://www.google.com/search?q='+ document.getElementById('q').value.split(' ').join('+'); return false">
|
<form onsubmit="window.location.href = '/get?url=https://www.google.com/search?q='+ document.getElementById('q').value.split(' ').join('+'); return false">
|
||||||
<input type="text" name="q" id="q" value="${search?.value}">
|
<input type="text" name="q" id="q" value="${search?.value}">
|
||||||
@ -76,7 +54,7 @@ export default async function google(
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: `${searchForm}${content.join("")}${navigation}`,
|
content: `${searchForm}${content.join("")}`,
|
||||||
textContent: textContent.join("\n"),
|
textContent: textContent.join("\n"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user