2024-05-25 12:03:37 +08:00
|
|
|
|
let isRead = localStorage.getItem('readChecked') !== 'false'; // default to true
|
2024-05-25 11:59:38 +08:00
|
|
|
|
let isChoose = localStorage.getItem('chooseChecked') !== 'false';
|
2022-01-26 21:10:09 +08:00
|
|
|
|
|
2022-07-18 16:00:08 +08:00
|
|
|
|
function getWord() {
|
|
|
|
|
return window.getSelection ? window.getSelection() : document.selection.createRange().text;
|
2022-01-26 21:10:09 +08:00
|
|
|
|
}
|
2022-07-18 16:00:08 +08:00
|
|
|
|
|
|
|
|
|
function fillInWord() {
|
|
|
|
|
let word = getWord();
|
2023-05-25 17:35:31 +08:00
|
|
|
|
if (isRead) Reader.read(word, inputSlider.value);
|
2024-05-28 19:55:38 +08:00
|
|
|
|
if (!isChoose) {
|
|
|
|
|
if(isHighlight){
|
|
|
|
|
const element = document.getElementById("selected-words3");
|
|
|
|
|
element.value = element.value + " " + word;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-18 16:00:08 +08:00
|
|
|
|
const element = document.getElementById("selected-words");
|
2024-05-26 11:19:28 +08:00
|
|
|
|
localStorage.setItem('nowWords', element.value);
|
|
|
|
|
element.value = element.value + " " + word;
|
2024-05-25 11:59:38 +08:00
|
|
|
|
localStorage.setItem('selectedWords', element.value);
|
2022-07-18 16:00:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.getElementById("text-content").addEventListener("click", fillInWord, false);
|
|
|
|
|
|
2023-05-25 17:35:31 +08:00
|
|
|
|
const sliderValue = document.getElementById("rangeValue");
|
|
|
|
|
const inputSlider = document.getElementById("rangeComponent");
|
2022-07-18 16:00:08 +08:00
|
|
|
|
inputSlider.oninput = () => {
|
2023-05-25 17:35:31 +08:00
|
|
|
|
let value = inputSlider.value;
|
2022-07-18 16:00:08 +08:00
|
|
|
|
sliderValue.textContent = value + '×';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function onReadClick() {
|
2022-01-26 21:10:09 +08:00
|
|
|
|
isRead = !isRead;
|
2024-05-25 11:59:38 +08:00
|
|
|
|
localStorage.setItem('readChecked', isRead);
|
2022-01-26 21:10:09 +08:00
|
|
|
|
}
|
2022-07-18 16:00:08 +08:00
|
|
|
|
|
|
|
|
|
function onChooseClick() {
|
2022-01-26 21:10:09 +08:00
|
|
|
|
isChoose = !isChoose;
|
2024-05-25 11:59:38 +08:00
|
|
|
|
localStorage.setItem('chooseChecked', isChoose);
|
2022-07-18 16:00:08 +08:00
|
|
|
|
}
|
2024-05-25 11:59:38 +08:00
|
|
|
|
|
|
|
|
|
// 如果网页刷新,停止播放声音
|
|
|
|
|
if (performance.getEntriesByType("navigation")[0].type == "reload") {
|
|
|
|
|
Reader.stopRead();
|
|
|
|
|
}
|
|
|
|
|
|