Highlight rewrite
This commit is contained in:
parent
6f2b40d75a
commit
c6b2f65171
1 changed files with 133 additions and 84 deletions
159
pageUpdater.js
159
pageUpdater.js
|
@ -117,59 +117,18 @@ function highlighter(json, full = true, linkParent = false) {
|
|||
}
|
||||
}
|
||||
} else if (element.type == "text") {
|
||||
var index = 0
|
||||
for (let i = 0; i < highlightedWords.length; i++) {
|
||||
var dict = highlightedWords[i]
|
||||
for (let x = 0; x < dict.words.length; x++) {
|
||||
index += 1
|
||||
var term = dict.words[x];
|
||||
var termWordCount = term.split(" ").length
|
||||
var termProps = dict
|
||||
|
||||
var reg = term
|
||||
var reg = new RegExp(`(${term})`, "g")
|
||||
if (termProps.caseInsensitive) {
|
||||
reg = new RegExp(`(${term})`, "gi")
|
||||
}
|
||||
|
||||
element.content = element.content.replaceAll(`{${term}}`, "TEMPORARY_REPLACE")
|
||||
element.content = element.content.replaceAll(reg, "{TERM" + index + "}")
|
||||
element.content = element.content.replaceAll("TEMPORARY_REPLACE", `${term}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (full) {
|
||||
var index = 0
|
||||
for (let i = 0; i < highlightedWords.length; i++) {
|
||||
var dict = highlightedWords[i]
|
||||
for (let x = 0; x < dict.words.length; x++) {
|
||||
index += 1
|
||||
var termKey = "{TERM" + index + "}"
|
||||
var termProps = dict
|
||||
while (element.content.includes(termKey)) {
|
||||
var termIndex = element.content.indexOf(termKey)
|
||||
|
||||
var spanEnd = element.content.indexOf(" ", termIndex)
|
||||
|
||||
if (spanEnd == -1) {
|
||||
spanEnd = element.content.length
|
||||
}
|
||||
|
||||
var spanStart = element.content.substring(0, termIndex).lastIndexOf(" ") + 1
|
||||
|
||||
// if (highTable[index] == "ULTRAKILL") {
|
||||
// console.log(startContent, " ---- ", endContent)
|
||||
// }
|
||||
|
||||
var startContent = element.content.substring(spanStart - 1, termIndex)
|
||||
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)
|
||||
// }
|
||||
// else if (endContent.includes(")") && !startContent.includes("(")) {
|
||||
// spanStart = element.content.substring(0, spanStart).lastIndexOf("(")
|
||||
// startContent = element.content.substring(spanStart - 1, termIndex)
|
||||
// }
|
||||
|
||||
var style = termProps.style || ""
|
||||
var classes = termProps.classes || ""
|
||||
|
@ -187,7 +146,7 @@ function highlighter(json, full = true, linkParent = false) {
|
|||
var width = 2
|
||||
// style += `text-shadow: -1px -1px 0 ${termProps.outline}, 1px -1px 0 ${termProps.outline}, -1px 1px 0 ${termProps.outline}, 1px 1px 0 ${termProps.outline};`
|
||||
style += `-webkit-text-stroke: 1px ${termProps.outline};`
|
||||
// ^ Not in use because it looks bad :30
|
||||
// ^ Not in use because it looks bad :3
|
||||
}
|
||||
|
||||
if (termProps.bold) {
|
||||
|
@ -202,27 +161,117 @@ function highlighter(json, full = true, linkParent = false) {
|
|||
classes = `class="${classes}"`
|
||||
}
|
||||
|
||||
var stuff = (startContent + dict.words[x] + endContent).trim()
|
||||
|
||||
if (!stuff.includes("span")) {
|
||||
var replacement = `<span ${style} ${classes}>${stuff}</span>`
|
||||
var splitContent = element.content.split(" ")
|
||||
for (let y = 0; y < splitContent.length; y++) {
|
||||
var word = splitContent[y]
|
||||
|
||||
if (reg.test(word)) {
|
||||
|
||||
if (link && !linkParent) {
|
||||
replacement = `<a href="${link}">${replacement}</a>`
|
||||
// console.log(replacement)
|
||||
}
|
||||
element.content = element.content.substring(0, spanStart) + replacement + element.content.substring(spanEnd)
|
||||
splitContent[y] = `<a href="${link}">${splitContent[y]}</a>`
|
||||
} else {
|
||||
|
||||
element.content = element.content.replace(termKey, dict.words[x])
|
||||
}
|
||||
splitContent[y] = `<span ${style} ${classes}>${splitContent[y]}</span>`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// element.content = element.content.replaceAll(termKey, replacement)
|
||||
element.content = splitContent.join(" ")
|
||||
|
||||
|
||||
// element.content = element.content.replaceAll(`{${term}}`, "TEMPORARY_REPLACE")
|
||||
// element.content = element.content.replaceAll(reg, "{TERM" + index + "}")
|
||||
// element.content = element.content.replaceAll("TEMPORARY_REPLACE", `${term}`)
|
||||
}
|
||||
}
|
||||
|
||||
// if (full) {
|
||||
// var index = 0
|
||||
// for (let i = 0; i < highlightedWords.length; i++) {
|
||||
// var dict = highlightedWords[i]
|
||||
// for (let x = 0; x < dict.words.length; x++) {
|
||||
// index += 1
|
||||
// var termKey = "{TERM" + index + "}"
|
||||
// var termProps = dict
|
||||
// while (element.content.includes(termKey)) {
|
||||
// var termIndex = element.content.indexOf(termKey)
|
||||
|
||||
// var spanEnd = element.content.indexOf(" ", termIndex)
|
||||
|
||||
// if (spanEnd == -1) {
|
||||
// spanEnd = element.content.length
|
||||
// }
|
||||
|
||||
// var spanStart = element.content.substring(0, termIndex).lastIndexOf(" ") + 1
|
||||
|
||||
// // if (highTable[index] == "ULTRAKILL") {
|
||||
// // console.log(startContent, " ---- ", endContent)
|
||||
// // }
|
||||
|
||||
// var startContent = element.content.substring(spanStart - 1, termIndex)
|
||||
// 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)
|
||||
// // }
|
||||
// // else if (endContent.includes(")") && !startContent.includes("(")) {
|
||||
// // spanStart = element.content.substring(0, spanStart).lastIndexOf("(")
|
||||
// // startContent = element.content.substring(spanStart - 1, termIndex)
|
||||
// // }
|
||||
|
||||
// var style = termProps.style || ""
|
||||
// var classes = termProps.classes || ""
|
||||
// var link = termProps.link || ""
|
||||
|
||||
// if (termProps.color) {
|
||||
// style += `color: ${termProps.color};`
|
||||
// }
|
||||
|
||||
// if (termProps.italicized) {
|
||||
// style += "font-style: italic;"
|
||||
// }
|
||||
|
||||
// if (termProps.outline) {
|
||||
// var width = 2
|
||||
// // style += `text-shadow: -1px -1px 0 ${termProps.outline}, 1px -1px 0 ${termProps.outline}, -1px 1px 0 ${termProps.outline}, 1px 1px 0 ${termProps.outline};`
|
||||
// style += `-webkit-text-stroke: 1px ${termProps.outline};`
|
||||
// // ^ Not in use because it looks bad :30
|
||||
// }
|
||||
|
||||
// if (termProps.bold) {
|
||||
// classes += "bold"
|
||||
// }
|
||||
|
||||
// if (style.length > 2) {
|
||||
// style = `style="${style}"`
|
||||
// }
|
||||
|
||||
// if (classes.length > 2) {
|
||||
// classes = `class="${classes}"`
|
||||
// }
|
||||
|
||||
// var stuff = (startContent + dict.words[x] + endContent).trim()
|
||||
|
||||
// if (!stuff.includes("span")) {
|
||||
// var replacement = `<span ${style} ${classes}>${stuff}</span>`
|
||||
|
||||
// if (link && !linkParent) {
|
||||
// replacement = `<a href="${link}">${replacement}</a>`
|
||||
// // console.log(replacement)
|
||||
// }
|
||||
// element.content = element.content.substring(0, spanStart) + replacement + element.content.substring(spanEnd)
|
||||
// } else {
|
||||
|
||||
// element.content = element.content.replace(termKey, dict.words[x])
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // element.content = element.content.replaceAll(termKey, replacement)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
return json
|
||||
|
|
Loading…
Reference in a new issue