Merge pull request #53 from TxtDot/store-dom

Store parsed DOM in InputHandler
This commit is contained in:
Artemy Egorov 2023-09-20 14:11:38 +03:00 committed by GitHub
commit 0c83a9a60a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ export class HandlerInput {
private requestUrl: URL; private requestUrl: URL;
private engine?: string; private engine?: string;
private redirectPath: string; private redirectPath: string;
private dom?: JSDOM;
constructor( constructor(
data: string, data: string,
@ -23,9 +24,13 @@ export class HandlerInput {
} }
parseDom(): JSDOM { parseDom(): JSDOM {
const dom = new JSDOM(this.data, { url: this.url }); if (this.dom) {
return this.dom;
}
const links = dom.window.document.getElementsByTagName("a"); this.dom = new JSDOM(this.data, { url: this.url });
const links = this.dom.window.document.getElementsByTagName("a");
for (const link of links) { for (const link of links) {
try { try {
link.href = generateProxyUrl( link.href = generateProxyUrl(
@ -39,7 +44,7 @@ export class HandlerInput {
} }
} }
return dom; return this.dom;
} }
getUrl(): string { getUrl(): string {