From 1929c5509a549b7519ed008612251830eec5d4d5 Mon Sep 17 00:00:00 2001 From: lixiaofeng <2368272960@qq.com> Date: Mon, 27 May 2024 22:46:47 +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/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fillword.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 fillword.js diff --git a/fillword.js b/fillword.js new file mode 100644 index 0000000..f33a3bd --- /dev/null +++ b/fillword.js @@ -0,0 +1,43 @@ +let isRead = true; +let isChoose = true; +let highlightWords = ""; + +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) { + if(isHighlight){ + const element = document.getElementById("selected-words3"); + element.value = element.value + " " + word; + } + 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; +} + +// 如果网页刷新,停止播放声音 +if (performance.getEntriesByType("navigation")[0].type == "reload") { + Reader.stopRead(); +} \ No newline at end of file