Created
July 22, 2022 17:46
-
-
Save gbishop/a9fcc1cfa9164e66cc89586a5095df69 to your computer and use it in GitHub Desktop.
A hack to show how one might add bubbling to THR
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
// 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