Skip to content

Commit

Permalink
Store parsed DOM in InputHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkCat09 committed Sep 20, 2023
1 parent 66ae522 commit e5ccbfe
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/handlers/handler-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class HandlerInput {
private requestUrl: URL;
private engine?: string;
private redirectPath: string;
private dom?: JSDOM;

constructor(
data: string,
Expand All @@ -23,9 +24,13 @@ export class HandlerInput {
}

parseDom(): JSDOM {
const dom = new JSDOM(this.data, { url: this.url });
if (this.dom) {
return this.dom;
}

this.dom = new JSDOM(this.data, { url: this.url });

const links = dom.window.document.getElementsByTagName("a");
const links = this.dom.window.document.getElementsByTagName("a");
for (const link of links) {
try {
link.href = generateProxyUrl(
Expand All @@ -39,7 +44,7 @@ export class HandlerInput {
}
}

return dom;
return this.dom;
}

getUrl(): string {
Expand Down

0 comments on commit e5ccbfe

Please sign in to comment.