Use better variable names.

Bug477-ChenJingyi
Lan Hui 2022-07-18 15:57:23 +08:00
parent b0f1e707b1
commit 13b39cf85c
1 changed files with 9 additions and 9 deletions

View File

@ -1,8 +1,8 @@
let isRead = true;
let isChoose = true;
let reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
let cur_position = 0; // 朗读文本的当前位置
let orig_position = 0; // 朗读文本的初始位置
let current_position = 0; // 朗读文本的当前位置
let original_position = 0; // 朗读文本的初始位置
let to_speak = ""; // 朗读的初始内容
function getWord() {
@ -25,7 +25,7 @@ function makeUtterance(str, rate) {
msg.lang = "en-US"; // TODO: add language options menu
msg.onboundary = ev => {
if (ev.name == "word") {
cur_position = ev.charIndex;
current_position = ev.charIndex;
}
}
return msg;
@ -38,16 +38,16 @@ inputSlider.oninput = () => {
sliderValue.textContent = value + '×';
if (!reader.speaking) return;
reader.cancel();
let msg = makeUtterance(to_speak.substring(orig_position + cur_position), value);
orig_position = orig_position + cur_position;
cur_position = 0;
let msg = makeUtterance(to_speak.substring(original_position + current_position), value);
original_position = original_position + current_position;
current_position = 0;
reader.speak(msg);
};
function read(s) {
to_speak = s.toString();
orig_position = 0;
cur_position = 0;
original_position = 0;
current_position = 0;
let msg = makeUtterance(to_speak, inputSlider.value);
reader.speak(msg);
}
@ -61,4 +61,4 @@ function onReadClick() {
function onChooseClick() {
isChoose = !isChoose;
}
}