EnglishPal/app/static/js/fillword.js

36 lines
969 B
JavaScript
Raw Normal View History

let isRead = true;
let isChoose = true;
function getWord() {
return window.getSelection ? window.getSelection() : document.selection.createRange().text;
}
function fillInWord() {
let word = getWord();
if (isRead) Reader.read(word, inputSlider.value);
if (!isChoose) return;
2024-04-11 19:09:26 +08:00
let element = document.getElementById("selected-words");
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);
const sliderValue = document.getElementById("rangeValue");
const inputSlider = document.getElementById("rangeComponent");
inputSlider.oninput = () => {
let value = inputSlider.value;
sliderValue.textContent = value + '×';
};
function onReadClick() {
isRead = !isRead;
}
function onChooseClick() {
isChoose = !isChoose;
}