Skip to content

Commit

Permalink
feat(src content-script): remove \ escape from single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnord committed Apr 10, 2023
1 parent 709468d commit e1ddfe7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/content-script.ts
Expand Up @@ -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);
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit e1ddfe7

Please sign in to comment.