From e1ddfe7c962c88141f5a954f382ef24996f9b0ca Mon Sep 17 00:00:00 2001 From: Claire Nord Date: Sun, 9 Apr 2023 17:14:37 -0700 Subject: [PATCH] feat(src content-script): remove `\` escape from single quotes --- src/content-script.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/content-script.ts b/src/content-script.ts index 79aa9e6..145b525 100644 --- a/src/content-script.ts +++ b/src/content-script.ts @@ -144,11 +144,14 @@ function parseCorrectResponse(hoverElement: Element | undefined, name: string) { const start = mouseOverAttribute.indexOf(CORRECT_RESPONSE_PREFIX); const end = mouseOverAttribute.indexOf(CORRECT_RESPONSE_SUFFIX); if (start !== undefined && start !== -1 && end !== undefined && end !== -1) { - const correctResponse = mouseOverAttribute.substring( + const responseHtml = mouseOverAttribute.substring( start + CORRECT_RESPONSE_PREFIX.length, end ); - return correctResponse; + // Remove HTML tags + const responseStr = responseHtml.replace(/<[^>]*>/g, ""); + // Replace backslash-escaped quotes + return responseStr.replace(/\\'/g, "'"); } throw new NotFoundError("could not find correct response in element " + name); } @@ -172,9 +175,7 @@ class FinalBoardParser { const categoryDiv = roundDiv.querySelector(".category"); const mouseOverDiv = categoryDiv?.children[0]; - const answerHtml = parseCorrectResponse(mouseOverDiv, "final jeopardy"); - // Remove HTML tags from the answer - this.answer = answerHtml.replace(/<[^>]*>/g, ""); + this.answer = parseCorrectResponse(mouseOverDiv, "final jeopardy"); } jsonify() { @@ -303,9 +304,7 @@ class ClueParser { const mouseOverDiv = clueDiv.children[0]?.children[0]?.children[0]?.children[0]?.children[0]; try { - const answerHtml = parseCorrectResponse(mouseOverDiv, `clue ${i}, ${j}`); - // Remove HTML tags from the answer - this.answer = answerHtml.replace(/<[^>]*>/g, ""); + this.answer = parseCorrectResponse(mouseOverDiv, `clue ${i}, ${j}`); } catch (error: unknown) { if (isNotFoundError(error)) { this.answer = "Unrevealed";