1
0
Fork 0
Bug545-HuangHuiLing
1994836463@qq.com 2024-05-20 15:30:38 +08:00
parent 90ac789bb4
commit 9b3551bbc8
1 changed files with 15 additions and 0 deletions

View File

@ -27,6 +27,21 @@ function highLight() {
let dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list 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;
const list = allWords.split(" "); // 将所有的生词放入一个list中 const list = allWords.split(" "); // 将所有的生词放入一个list中
if(word !== null && word !== "" && word !== " "){
let articleContent_fb2 = articleContent;
if(localStorage.getItem("nowWord").indexOf(word) !== -1){
while(articleContent_fb2.toLowerCase().indexOf(word.toLowerCase()) !== -1){
// 找到副本中和list[i]匹配的第一个单词(第一种匹配情况),并赋值给list[i]。
const index = articleContent_fb2.toLowerCase().indexOf(word.toLowerCase());
word = articleContent_fb2.substring(index, index + word.length);
articleContent_fb2 = articleContent_fb2.substring(index + word.length); // 使用副本中list[i]之后的子串替换掉副本
articleContent = articleContent.replace(new RegExp("<mark>"+word+"</mark>", "g"), word)
}
pickedWords.value = localStorage.getItem("nowWord").replace(word,"");
document.getElementById("article").innerHTML = articleContent;
return;
}
}
let totalSet = new Set(); let totalSet = new Set();
for (let i = 0; i < list.length; ++i) { for (let i = 0; i < list.length; ++i) {
list[i] = list[i].replace(/(^\W*)|(\W*$)/g, ""); // 消除单词两边的非单词字符 list[i] = list[i].replace(/(^\W*)|(\W*$)/g, ""); // 消除单词两边的非单词字符