From 8fb52915cab4e4e9096b1ccc1d27cfd84fa3e389 Mon Sep 17 00:00:00 2001
From: lixiaofeng <2368272960@qq.com>
Date: Mon, 27 May 2024 22:46:08 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?=
=?UTF-8?q?=20app/static/js?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/static/js/highlight.js | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
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