From 8924166975aeb7517efc14e1aed5b1af1aeb8bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=83=E8=89=B3=E7=BE=8E?= <3183597872@qq.com> Date: Sun, 12 Jun 2022 21:23:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'static\js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "static\\js/fillword.js" | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "static\\js/fillword.js" diff --git "a/static\\js/fillword.js" "b/static\\js/fillword.js" new file mode 100644 index 0000000..9843331 --- /dev/null +++ "b/static\\js/fillword.js" @@ -0,0 +1,32 @@ +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; +} +