Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created September 22, 2018 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/5ed1a23b72e6c5dd1e455685d958cf5c to your computer and use it in GitHub Desktop.
Save kyanny/5ed1a23b72e6c5dd1e455685d958cf5c to your computer and use it in GitHub Desktop.
Speech it
var current = null;
var originalStyle = '';
document.onmouseover = function(e) {
current = document.elementFromPoint(e.clientX, e.clientY);
originalStyle = current.style;
current.style = 'background: rgba(255, 0, 0, 0.2)';
if (window.speechSynthesis) {
var synth = speechSynthesis;
var message = current.textContent;
var utter = new SpeechSynthesisUtterance(message);
utter.lang = "ja-JP";
current.onmouseup = function(ev) {
ev.stopPropagation();
synth.speak(utter);
}
}
}
document.onmouseout = function(e) {
current.style = originalStyle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment