From 9b3551bbc841538a9d37aed0409d3baa5ed6288d Mon Sep 17 00:00:00 2001 From: "1994836463@qq.com" Date: Mon, 20 May 2024 15:30:38 +0800 Subject: [PATCH] fix --- app/static/js/highlight.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index e8a3cf8..e776bb3 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -27,6 +27,21 @@ function highLight() { 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; 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(""+word+"", "g"), word) + } + pickedWords.value = localStorage.getItem("nowWord").replace(word,""); + document.getElementById("article").innerHTML = articleContent; + return; + } + } let totalSet = new Set(); for (let i = 0; i < list.length; ++i) { list[i] = list[i].replace(/(^\W*)|(\W*$)/g, ""); // 消除单词两边的非单词字符