Compare commits

...

7 Commits

3 changed files with 39 additions and 3 deletions

View File

@ -65,4 +65,7 @@ function onChooseClick() {
function stopRead() {
reader.cancel();
}
}
if (performance.navigation.type == 1) { //如果网页刷新,停止播放声音
stopRead()
}

View File

@ -0,0 +1,33 @@
isRead = true;
isChoose = true;
var reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
reader.cancel();// 初始化时清空reader列表
function getWord(){
var word = window.getSelection?window.getSelection():document.selection.createRange().text;
return word;
}
function fillinWord(){
var word = getWord();
if (isRead) read(word);
if (!isChoose) return;
var element = document.getElementById("selected-words");
element.value = element.value + " " + word;
}
document.getElementById("text-content").addEventListener("click", fillinWord, false);
function read(s){
var msg = new SpeechSynthesisUtterance(s);
reader.speak(msg);
console.log("+++++++++++++");
}
function onReadClick(){
isRead = !isRead;
if(!isRead){
reader.cancel();
}
}
function onChooseClick(){
isChoose = !isChoose;
}

View File

@ -47,9 +47,9 @@
{# <div class="alert alert-warning" role="alert">Congratulations! {{ message }}</div>#}
{# {% endfor %}#}
<a class="btn btn-success" href="/{{ username }}/reset" role="button"> 下一篇 Next Article </a>
<a class="btn btn-success" href="/{{ username }}/reset" role="button" onclick="stopRead()"> 下一篇 Next Article </a>
{% if session.get('existing_articles') != None and session.get('existing_articles')["index"] !=0 %}
<a class="btn btn-success" href="/{{ username }}/back" role="button"> 上一篇 Previous Article </a>
<a class="btn btn-success" href="/{{ username }}/back" role="button" onclick="stopRead()"> 上一篇 Previous Article </a>
{% endif %}
<p><b>阅读文章并回答问题</b></p>