1
0
Fork 0
EnglishPal/app/static/js/fillword.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

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';
function getWord() {
return window.getSelection ? window.getSelection() : document.selection.createRange().text;
}
function fillInWord() {
let word = getWord();
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;
}
const element = document.getElementById("selected-words");
localStorage.setItem('nowWords', element.value);
element.value = element.value + " " + word;
2024-05-25 11:59:38 +08:00
localStorage.setItem('selectedWords', element.value);
}
document.getElementById("text-content").addEventListener("click", fillInWord, false);
const sliderValue = document.getElementById("rangeValue");
const inputSlider = document.getElementById("rangeComponent");
inputSlider.oninput = () => {
let value = inputSlider.value;
sliderValue.textContent = value + '×';
};
function onReadClick() {
isRead = !isRead;
2024-05-25 11:59:38 +08:00
localStorage.setItem('readChecked', isRead);
}
function onChooseClick() {
isChoose = !isChoose;
2024-05-25 11:59:38 +08:00
localStorage.setItem('chooseChecked', isChoose);
}
2024-05-25 11:59:38 +08:00
// 如果网页刷新,停止播放声音
if (performance.getEntriesByType("navigation")[0].type == "reload") {
Reader.stopRead();
}