上传文件至 app/static/js

pull/127/head
lixiaofeng 2024-05-27 22:46:08 +08:00
parent d8e4fbbb2d
commit 8fb52915ca
1 changed files with 7 additions and 7 deletions

View File

@ -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的地方改为"<span class='highlighted'>" + word + "</span>"。
// 将文章中所有出现该单词word的地方改为"<mark>" + word + "<mark>"。
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;
}
function cancelHighlighting() {
@ -74,7 +75,6 @@ function toggleHighlighting() {
isHighlight = true;
highLight();
}
localStorage.setItem('highlightChecked', isHighlight);
}
showBtnHandler();