Refactor: remove duplicate code block
parent
b5dacb9ad2
commit
8cb34e56ba
|
@ -25,8 +25,8 @@ function highLight() {
|
||||||
let articleContent = document.getElementById("article").innerText;
|
let articleContent = document.getElementById("article").innerText;
|
||||||
let pickedWords = document.getElementById("selected-words"); // words picked to the text area
|
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 dictionaryWords = document.getElementById("selected-words2"); // words appearing in the user's new words list
|
||||||
if (pickedWords != null) {
|
let allWords = pickedWords.value + " " + dictionaryWords.value;
|
||||||
const list = pickedWords.value.split(" ");
|
const list = allWords.split(" ");
|
||||||
for (let i = 0; i < list.length; ++i) {
|
for (let i = 0; i < list.length; ++i) {
|
||||||
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除单词两边的空字符
|
list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除单词两边的空字符
|
||||||
if (list[i] !== "" && "<mark>".indexOf(list[i]) === -1 && "</mark>".indexOf(list[i]) === -1) {
|
if (list[i] !== "" && "<mark>".indexOf(list[i]) === -1 && "</mark>".indexOf(list[i]) === -1) {
|
||||||
|
@ -34,16 +34,6 @@ function highLight() {
|
||||||
articleContent = articleContent.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " <mark>" + list[i] + "</mark> ");
|
articleContent = articleContent.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " <mark>" + list[i] + "</mark> ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (dictionaryWords != null) {
|
|
||||||
const list2 = dictionaryWords.value.split(" ");
|
|
||||||
for (let i = 0; i < list2.length; ++i) {
|
|
||||||
list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, "");
|
|
||||||
if (list2[i] !== "" && "<mark>".indexOf(list2[i]) === -1 && "</mark>".indexOf(list2[i]) === -1) {
|
|
||||||
articleContent = articleContent.replace(new RegExp("\\s"+list2[i]+"\\s", "g"), " <mark>" + list2[i] + "</mark> ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
document.getElementById("article").innerHTML = articleContent;
|
document.getElementById("article").innerHTML = articleContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue