Compare commits
3 Commits
3373ba1429
...
9b3551bbc8
Author | SHA1 | Date |
---|---|---|
|
9b3551bbc8 | |
|
90ac789bb4 | |
|
8575a0dc33 |
|
@ -1,6 +1,5 @@
|
|||
// initialize from localStorage
|
||||
let isRead = localStorage.getItem('readChecked') !== 'false'; // default to true
|
||||
let isChoose = localStorage.getItem('chooseChecked') !== 'false';
|
||||
let isRead = true;
|
||||
let isChoose = true;
|
||||
|
||||
function getWord() {
|
||||
return window.getSelection ? window.getSelection() : document.selection.createRange().text;
|
||||
|
@ -11,8 +10,11 @@ function fillInWord() {
|
|||
if (isRead) Reader.read(word, inputSlider.value);
|
||||
if (!isChoose) return;
|
||||
const element = document.getElementById("selected-words");
|
||||
element.value = element.value + " " + word;
|
||||
localStorage.setItem('selectedWords', element.value);
|
||||
let index = (String)(element.value).indexOf(word);
|
||||
localStorage.setItem("nowWord",element.value);
|
||||
if(index === -1){
|
||||
element.value = element.value + " " + word;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("text-content").addEventListener("click", fillInWord, false);
|
||||
|
@ -26,15 +28,8 @@ inputSlider.oninput = () => {
|
|||
|
||||
function onReadClick() {
|
||||
isRead = !isRead;
|
||||
localStorage.setItem('readChecked', isRead);
|
||||
}
|
||||
|
||||
function onChooseClick() {
|
||||
isChoose = !isChoose;
|
||||
localStorage.setItem('chooseChecked', isChoose);
|
||||
}
|
||||
|
||||
// 如果网页刷新,停止播放声音
|
||||
if (performance.getEntriesByType("navigation")[0].type == "reload") {
|
||||
Reader.stopRead();
|
||||
}
|
||||
|
|
|
@ -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("<mark>"+word+"</mark>", "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, ""); // 消除单词两边的非单词字符
|
||||
|
|
Loading…
Reference in New Issue