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

37 lines
1.0 KiB
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;
const element = document.getElementById("selected-words");
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;
}
// 如果网页刷新,停止播放声音
2023-06-05 08:37:31 +08:00
// performance.navigation.type 以弃用改为了performance.getEntriesByType("navigation")[0].type
if (performance.getEntriesByType("navigation")[0].type == "reload") {
Reader.stopRead();
}