上传文件至 app/static/js
parent
d8e4fbbb2d
commit
8fb52915ca
|
@ -1,4 +1,4 @@
|
||||||
let isHighlight = localStorage.getItem('highlightChecked') !== 'false'; // default to true
|
let isHighlight = true;
|
||||||
|
|
||||||
function cancelBtnHandler() {
|
function cancelBtnHandler() {
|
||||||
cancelHighlighting();
|
cancelHighlighting();
|
||||||
|
@ -25,7 +25,9 @@ function highLight() {
|
||||||
let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器
|
let articleContent = document.getElementById("article").innerHTML; // innerHTML保留HTML标签来保持部分格式,且适配不同的浏览器
|
||||||
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
|
||||||
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中
|
const list = allWords.split(" "); // 将所有的生词放入一个list中
|
||||||
let totalSet = new Set();
|
let totalSet = new Set();
|
||||||
for (let i = 0; i < list.length; ++i) {
|
for (let i = 0; i < list.length; ++i) {
|
||||||
|
@ -39,16 +41,15 @@ function highLight() {
|
||||||
}
|
}
|
||||||
totalSet = new Set([...totalSet, ...matches]);
|
totalSet = new Set([...totalSet, ...matches]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 删除所有的mark标签,防止标签发生嵌套
|
// 删除所有的mark标签,防止标签发生嵌套
|
||||||
articleContent = articleContent.replace(/<(mark)[^>]*>/gi, "");
|
articleContent = articleContent.replace(/<(mark)[^>]*>/gi, "");
|
||||||
articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, "");
|
articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, "");
|
||||||
// 将文章中所有出现该单词word的地方改为:"<span class='highlighted'>" + word + "</span>"。
|
// 将文章中所有出现该单词word的地方改为:"<mark>" + word + "<mark>"。
|
||||||
for (let word of totalSet) {
|
for (let word of totalSet) {
|
||||||
articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "<span class='highlighted'>" + word + "</span>");
|
articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "<mark>" + word + "</mark>");
|
||||||
}
|
}
|
||||||
document.getElementById("article").innerHTML = articleContent;
|
document.getElementById("article").innerHTML = articleContent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelHighlighting() {
|
function cancelHighlighting() {
|
||||||
|
@ -74,7 +75,6 @@ function toggleHighlighting() {
|
||||||
isHighlight = true;
|
isHighlight = true;
|
||||||
highLight();
|
highLight();
|
||||||
}
|
}
|
||||||
localStorage.setItem('highlightChecked', isHighlight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showBtnHandler();
|
showBtnHandler();
|
Loading…
Reference in New Issue