From 1d6696999a5f82b5e211e1ae2a29aa637b49bdc4 Mon Sep 17 00:00:00 2001 From: bingus_violet Date: Wed, 13 Nov 2024 23:31:53 -0600 Subject: [PATCH] Continuing to pollute and overcomplicate the highlight system --- pageUpdater.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pageUpdater.js b/pageUpdater.js index 67ddf71..37e6a48 100644 --- a/pageUpdater.js +++ b/pageUpdater.js @@ -146,15 +146,17 @@ function highlighter(json, full = true, linkParent = false) { var termKey = "{TERM" + index + "}" var termProps = dict while (element.content.includes(termKey)) { + var endRegex = " " + var termIndex = element.content.indexOf(termKey) - var spanEnd = element.content.indexOf(" ", termIndex) + var spanEnd = element.content.indexOf(endRegex, termIndex) if (spanEnd == -1) { spanEnd = element.content.length } - var spanStart = element.content.substring(0, termIndex).lastIndexOf(" ") + 1 + var spanStart = element.content.substring(0, termIndex).lastIndexOf(endRegex) + 1 // if (highTable[index] == "ULTRAKILL") { // console.log(startContent, " ---- ", endContent) @@ -164,12 +166,27 @@ function highlighter(json, full = true, linkParent = false) { var endContent = element.content.substring(termIndex + termKey.length, spanEnd) if (startContent.includes("(") && !endContent.includes(")")) { - spanEnd = element.content.indexOf(")", spanStart) + 1 - endContent = element.content.substring(termIndex + termKey.length, spanEnd) + var newSpanEnd = element.content.indexOf(")", spanStart) + 1 + var newEndContent = element.content.substring(termIndex + termKey.length, newSpanEnd) + if (newEndContent.includes("<") || newEndContent.includes("TERM")) { + spanStart += 1 + startContent = startContent.substring(2) + } else { + spanEnd = newSpanEnd + endContent = newEndContent + } } else if (endContent.includes(")") && !startContent.includes("(")) { - spanStart = element.content.substring(0, spanStart).lastIndexOf("(") - startContent = element.content.substring(spanStart - 1, termIndex) + var newSpanStart = element.content.substring(0, spanStart).lastIndexOf("(") + var newStartContent = element.content.substring(newSpanStart - 1, termIndex) + if (newStartContent.includes("<") || newStartContent.includes("TERM")) { + spanEnd -= 1 + endContent = endContent.substring(0, endContent.length - 1) + } else { + console.log(newStartContent) + spanStart = newSpanStart + startContent = newStartContent + } } var style = termProps.style || ""