Skip to content

Instantly share code, notes, and snippets.

@gbishop
Created July 22, 2022 17:46
Show Gist options
  • Save gbishop/a9fcc1cfa9164e66cc89586a5095df69 to your computer and use it in GitHub Desktop.
Save gbishop/a9fcc1cfa9164e66cc89586a5095df69 to your computer and use it in GitHub Desktop.
A hack to show how one might add bubbling to THR
// kill any saved interval to make dev easier
if (window.interval) clearInterval(window.interval);
// remember the current url
let url = null;
// Call our read function when the URL changes (there must be a better way)
function pollURL() {
if (document.location.href != url) {
url = document.location.href;
readIt();
}
}
// If we find THR text on the page, bubble it
function readIt() {
const textBox = document.querySelector(".thr-text");
if (textBox) {
bubble(textBox);
}
}
// Bubble the text in here.
function bubble(textBox) {
const text = textBox.innerText;
const utterance = new SpeechSynthesisUtterance(text);
utterance.addEventListener('boundary', (e) => console.log('b', e));
speechSynthesis.speak(utterance);
}
window.interval = setInterval(pollURL, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment