Skip to content

Instantly share code, notes, and snippets.

@rockonyu
Last active March 17, 2022 08:17
Show Gist options
  • Save rockonyu/b0ac44989a4aa8603733904397f0f568 to your computer and use it in GitHub Desktop.
Save rockonyu/b0ac44989a4aa8603733904397f0f568 to your computer and use it in GitHub Desktop.
將程式碼加入書籤,可以唸出當前滑鼠選擇的文字。
javascript: (() => {
const synth = window.speechSynthesis;
if (synth.speaking) {
synth.cancel();
return;
}
const selectedText = window.getSelection().toString();
if (!selectedText) {
return;
}
synth.speak(new SpeechSynthesisUtterance(selectedText))
})();
(()=>{const e=window.speechSynthesis;if(e.speaking)return void e.cancel();const n=window.getSelection().toString();n&&e.speak(new SpeechSynthesisUtterance(n))})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment