diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js
index c9c3a02..f0680af 100644
--- a/app/static/js/highlight.js
+++ b/app/static/js/highlight.js
@@ -1,4 +1,4 @@
-let isHighlight = localStorage.getItem('highlightChecked') !== 'false'; // default to true
+let isHighlight = true;
function cancelBtnHandler() {
cancelHighlighting();
@@ -25,7 +25,9 @@ function highLight() {
let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器
let pickedWords = document.getElementById("selected-words"); // words picked to the text area
let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list
- let allWords = dictionaryWords === null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value;
+ let allWords = dictionaryWords == null ? pickedWords.value + " " : pickedWords.value + " " + dictionaryWords.value;
+ highlightWords = document.getElementById("selected-words3");
+ allWords = highlightWords == null ? allWords : allWords + " " + highlightWords.value;
const list = allWords.split(" "); // 将所有的生词放入一个list中
let totalSet = new Set();
for (let i = 0; i < list.length; ++i) {
@@ -39,16 +41,15 @@ function highLight() {
}
totalSet = new Set([...totalSet, ...matches]);
}
- }
+ }
// 删除所有的mark标签,防止标签发生嵌套
articleContent = articleContent.replace(/<(mark)[^>]*>/gi, "");
articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, "");
- // 将文章中所有出现该单词word的地方改为:"" + word + ""。
+ // 将文章中所有出现该单词word的地方改为:"" + word + ""。
for (let word of totalSet) {
- articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "" + word + "");
+ articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "" + word + "");
}
document.getElementById("article").innerHTML = articleContent;
-
}
function cancelHighlighting() {
@@ -74,7 +75,6 @@ function toggleHighlighting() {
isHighlight = true;
highLight();
}
- localStorage.setItem('highlightChecked', isHighlight);
}
showBtnHandler();
\ No newline at end of file