Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
veks committed Aug 24, 2021
1 parent 5563885 commit 0a7dc31
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dist/js/bvi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/bvi.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/js/bvi.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/bvi.min.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/js/bvi.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,11 +816,11 @@ class Bvi {
return str.slice(left, right + pos)
}

let voices = synth().getVoices()
let chunkLength = 120
let patternRegex = new RegExp('^[\\s\\S]{' + Math.floor(chunkLength / 2) + ',' + chunkLength + '}[.!?,]{1}|^[\\s\\S]{1,' + chunkLength + '}$|^[\\s\\S]{1,' + chunkLength + '} ')
let array = []
let $text = text
let voices = synth().getVoices()

while ($text.length > 0) {
array.push($text.match(patternRegex)[0])
Expand All @@ -845,18 +845,19 @@ class Bvi {
}

if (echo) {
utter.onboundary = function (event) {
utter.onboundary = event => {

element.classList.add('bvi-highlighting')
let world = getWordAt(event.utterance.text, event.charIndex)
let textContent = element.textContent
let term = world.replace(/(\s+)/, '(<[^>]+>)*$1(<[^>]+>)*')
let term = world.replace(/(\s+)/, '((<[^>]+>)*$1(<[^>]+>)*)')
let pattern = new RegExp('(' + term + ')', 'gi')
textContent = textContent.replace(pattern, '<mark>$1</mark>')
textContent = textContent.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, '$1</mark>$2<mark>$4')
element.innerHTML = textContent
}

utter.onend = function (event) {
utter.onend = event => {
element.classList.remove('bvi-highlighting')
let textContent = element.textContent
textContent = textContent.replace(/(<mark>$1<\/mark>)/, '$1')
Expand Down

0 comments on commit 0a7dc31

Please sign in to comment.