Adapted engines to work with HandlerInput
This commit is contained in:
parent
456a472031
commit
bbbfe480eb
@ -1,12 +1,14 @@
|
|||||||
import { DOMWindow } from "jsdom";
|
import { HandlerInput } from "./handler-input";
|
||||||
import { IHandlerOutput } from "./handler.interface";
|
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(
|
||||||
window: DOMWindow,
|
input: HandlerInput,
|
||||||
): Promise<IHandlerOutput> {
|
): Promise<IHandlerOutput> {
|
||||||
|
const document = input.parseDom().window.document;
|
||||||
|
|
||||||
const googleAnchors = [
|
const googleAnchors = [
|
||||||
...window.document.querySelectorAll("a[jsname=ACyKwe]"),
|
...document.querySelectorAll("a[jsname=ACyKwe]"),
|
||||||
] as HTMLAnchorElement[];
|
] as HTMLAnchorElement[];
|
||||||
|
|
||||||
if (!googleAnchors) {
|
if (!googleAnchors) {
|
||||||
|
@ -2,15 +2,12 @@ import { IHandlerOutput } from "./handler.interface";
|
|||||||
import { Engines, EngineFunction, EnginesMatch } from "../types/handlers";
|
import { Engines, EngineFunction, EnginesMatch } from "../types/handlers";
|
||||||
import axios from "../types/axios";
|
import axios from "../types/axios";
|
||||||
|
|
||||||
import { JSDOM } from "jsdom";
|
|
||||||
|
|
||||||
import micromatch from "micromatch";
|
import micromatch from "micromatch";
|
||||||
|
|
||||||
import readability from "./readability";
|
import readability from "./readability";
|
||||||
import google, { GoogleDomains } from "./google";
|
import google, { GoogleDomains } from "./google";
|
||||||
import stackoverflow, { StackOverflowDomains } from "./stackoverflow/main";
|
import stackoverflow, { StackOverflowDomains } from "./stackoverflow/main";
|
||||||
|
|
||||||
import { generateProxyUrl } from "../utils/generate";
|
|
||||||
import isLocalResource from "../utils/islocal";
|
import isLocalResource from "../utils/islocal";
|
||||||
|
|
||||||
import { LocalResourceError, NotHtmlMimetypeError } from "../errors/main";
|
import { LocalResourceError, NotHtmlMimetypeError } from "../errors/main";
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { Readability } from "@mozilla/readability";
|
import { Readability } from "@mozilla/readability";
|
||||||
|
import { HandlerInput } from "./handler-input";
|
||||||
import { IHandlerOutput } from "./handler.interface";
|
import { IHandlerOutput } from "./handler.interface";
|
||||||
import { DOMWindow } from "jsdom";
|
|
||||||
import { EngineParseError } from "../errors/main";
|
import { EngineParseError } from "../errors/main";
|
||||||
|
|
||||||
export default async function readability(
|
export default async function readability(
|
||||||
window: DOMWindow
|
input: HandlerInput,
|
||||||
): Promise<IHandlerOutput> {
|
): Promise<IHandlerOutput> {
|
||||||
const reader = new Readability(window.document);
|
const reader = new Readability(input.parseDom().window.document);
|
||||||
const parsed = reader.parse();
|
const parsed = reader.parse();
|
||||||
|
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
|
import { HandlerInput } from "../handler-input";
|
||||||
import { IHandlerOutput } from "../handler.interface";
|
import { IHandlerOutput } from "../handler.interface";
|
||||||
import { DOMWindow } from "jsdom";
|
|
||||||
import { EngineParseError } from "../../errors/main";
|
import { EngineParseError } from "../../errors/main";
|
||||||
import qPostsHandler from "./questions-posts";
|
import qPostsHandler from "./questions-posts";
|
||||||
|
|
||||||
export default async function stackoverflow(
|
export default async function stackoverflow(
|
||||||
window: DOMWindow,
|
input: HandlerInput,
|
||||||
): Promise<IHandlerOutput> {
|
): Promise<IHandlerOutput> {
|
||||||
const url = new URL(window.location.href);
|
const window = input.parseDom().window;
|
||||||
|
|
||||||
|
const url = new URL(window.location.href);
|
||||||
const path = url.pathname.split("/").filter((p) => p !== "");
|
const path = url.pathname.split("/").filter((p) => p !== "");
|
||||||
|
|
||||||
let result: IHandlerOutput = {
|
let result: IHandlerOutput = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user