forked from mrlan/EnglishPal
				
			Stop reading when user clicks the next or previous button and also selecting new text(s)
							parent
							
								
									dabeb0d2a9
								
							
						
					
					
						commit
						9d9590328d
					
				|  | @ -2,7 +2,6 @@ var isRead = true; | ||||||
| var isChoose = true; | var isChoose = true; | ||||||
| const reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
 | const reader = window.speechSynthesis; // 全局定义朗读者,以便朗读和暂停
 | ||||||
| //获取字符
 | //获取字符
 | ||||||
| <<<<<<< HEAD |  | ||||||
| function getWord() { | function getWord() { | ||||||
|   return window.getSelection |   return window.getSelection | ||||||
|     ? window.getSelection() |     ? window.getSelection() | ||||||
|  | @ -39,41 +38,3 @@ function onReadClick() { | ||||||
| function onChooseClick() { | function onChooseClick() { | ||||||
|   isChoose = !isChoose; |   isChoose = !isChoose; | ||||||
| } | } | ||||||
| 
 |  | ||||||
| function stopRead() { |  | ||||||
|   reader.cancel(); |  | ||||||
| } |  | ||||||
| ======= |  | ||||||
| function getWord(){ |  | ||||||
|    return window.getSelection?window.getSelection():document.selection.createRange().text; |  | ||||||
| } |  | ||||||
| //填充字符
 |  | ||||||
| function fillingWord(){ |  | ||||||
|    let word = getWord(); |  | ||||||
|    if (isRead) read(word); |  | ||||||
|    if (!isChoose) return; |  | ||||||
|    let element = document.getElementById("selected-words"); |  | ||||||
|    element.value = element.value + " " + word; |  | ||||||
| } |  | ||||||
| document.getElementById("text-content").addEventListener("click", fillingWord, false); |  | ||||||
| //朗读单词
 |  | ||||||
| //@word 要朗读的单词
 |  | ||||||
| function read(word){ |  | ||||||
|    //关闭当前正在读的单词
 |  | ||||||
|    reader.cancel() |  | ||||||
|    //创建新的朗读任务
 |  | ||||||
|    let msg = new SpeechSynthesisUtterance(word); |  | ||||||
|    reader.speak(msg); |  | ||||||
| } |  | ||||||
| //关闭正在读的单词
 |  | ||||||
| function onReadClick(){ |  | ||||||
|     let isRead = !isRead; |  | ||||||
|     if(!isRead){ |  | ||||||
|        reader.cancel(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| //取消当前选择
 |  | ||||||
| function onChooseClick(){ |  | ||||||
|     isChoose = !isChoose; |  | ||||||
| } |  | ||||||
| >>>>>>> 72e23f4e13a8ee98628529dbfc2e21c339757015 |  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue