Compare commits
2 Commits
master
...
Bug407-Jin
Author | SHA1 | Date |
---|---|---|
AAAzsf | 72e23f4e13 | |
AAAzsf | 5a62204864 |
|
@ -1,29 +1,36 @@
|
||||||
isRead = true;
|
var isRead = true;
|
||||||
isChoose = true;
|
var isChoose = true;
|
||||||
var reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
|
const reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
|
||||||
|
//获取字符
|
||||||
function getWord(){
|
function getWord(){
|
||||||
var word = window.getSelection?window.getSelection():document.selection.createRange().text;
|
return window.getSelection?window.getSelection():document.selection.createRange().text;
|
||||||
return word;
|
|
||||||
}
|
}
|
||||||
function fillinWord(){
|
//填充字符
|
||||||
var word = getWord();
|
function fillingWord(){
|
||||||
|
let word = getWord();
|
||||||
if (isRead) read(word);
|
if (isRead) read(word);
|
||||||
if (!isChoose) return;
|
if (!isChoose) return;
|
||||||
var element = document.getElementById("selected-words");
|
let element = document.getElementById("selected-words");
|
||||||
element.value = element.value + " " + word;
|
element.value = element.value + " " + word;
|
||||||
}
|
}
|
||||||
document.getElementById("text-content").addEventListener("click", fillinWord, false);
|
document.getElementById("text-content").addEventListener("click", fillingWord, false);
|
||||||
function read(s){
|
//朗读单词
|
||||||
var msg = new SpeechSynthesisUtterance(s);
|
//@word 要朗读的单词
|
||||||
|
function read(word){
|
||||||
|
//关闭当前正在读的单词
|
||||||
|
reader.cancel()
|
||||||
|
//创建新的朗读任务
|
||||||
|
let msg = new SpeechSynthesisUtterance(word);
|
||||||
reader.speak(msg);
|
reader.speak(msg);
|
||||||
}
|
}
|
||||||
|
//关闭正在读的单词
|
||||||
function onReadClick(){
|
function onReadClick(){
|
||||||
isRead = !isRead;
|
let isRead = !isRead;
|
||||||
if(!isRead){
|
if(!isRead){
|
||||||
reader.cancel();
|
reader.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//取消当前选择
|
||||||
function onChooseClick(){
|
function onChooseClick(){
|
||||||
isChoose = !isChoose;
|
isChoose = !isChoose;
|
||||||
}
|
}
|
Loading…
Reference in New Issue