Store parsed DOM in InputHandler

This commit is contained in:
DarkCat09 2023-09-20 12:03:44 +04:00
parent 66ae5226b7
commit e5ccbfe434
No known key found for this signature in database
GPG Key ID: 0A26CD5B3345D6E3

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 {