Skip to content

Commit

Permalink
Merge pull request #53 from TxtDot/store-dom
Browse files Browse the repository at this point in the history
Store parsed DOM in InputHandler
  • Loading branch information
artegoser authored Sep 20, 2023
2 parents 66ae522 + e5ccbfe commit 0c83a9a
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 0c83a9a

Please sign in to comment.