Last active
June 29, 2020 15:59
-
-
Save jt3k/65fb1bac483ab617f507c4220f597098 to your computer and use it in GitHub Desktop.
Voice over of the next word at https://www.keybr.com/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This snippet adds voice-over to the next word in the event of a spacebar or erroneous press | |
// To sound after an error, you will need to enable "Settings → Miscellaneous → Forgive errors" | |
// How to use ? | |
// 1. Open https://www.keybr.com/ | |
// 2. Press Ctrl+Shift+I (or F12) to open devTools | |
// 3. Paste this code into the console | |
// 4. Close the devTools | |
// 5. Enjoy | |
function getNextWord() { | |
let nextWord = ''; | |
let letter = document.querySelector('.TextInput-item--cursor'); | |
// when "Network error" | |
if(!letter) { | |
return; | |
} | |
do { | |
nextWord += letter.textContent; | |
letter = letter.nextElementSibling; | |
} while ( | |
letter && | |
letter.classList.contains('TextInput-item--special') === false | |
); | |
return nextWord; | |
} | |
document.onkeydown = ({ code }) => { | |
if (window.speechSynthesis.speaking) { | |
return; | |
} | |
// const isNextSpace = document.querySelector('.TextInput-item--cursor').nextElementSibling.classList.contains('TextInput-item--special'); | |
// if(isNextSpace) { | |
// console.log(getNextWord()); | |
// } | |
const isWrongLetter = document.querySelector('.TextInput-item--garbage'); | |
if (code === 'Space' || isWrongLetter) { | |
const word = getNextWord(); | |
console.log(word); | |
const utter = new SpeechSynthesisUtterance(word); | |
window.speechSynthesis.speak(utter); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment