summaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 14:50:21 -0500
committerGitHub <noreply@github.com>2020-02-22 14:50:21 -0500
commitf8f03f3af0ab031cc58bf5ad3f782c8d45137430 (patch)
tree3116b3a9429077d77f16d374835ab768d8b0d9d4 /ext/mixed
parentf3c4b0e1e14cbdfb86c692e89144c762801b2339 (diff)
parent418e7f9968ba8a6e302ec1e1b6d7dafe4b85fd97 (diff)
Merge pull request #362 from toasted-nutbread/more-type-refactoring
More type refactoring
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/audio.js16
-rw-r--r--ext/mixed/js/text-scanner.js19
2 files changed, 14 insertions, 21 deletions
diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js
index 47db5c75..fe5982dd 100644
--- a/ext/mixed/js/audio.js
+++ b/ext/mixed/js/audio.js
@@ -72,19 +72,15 @@ class TextToSpeechAudio {
const m = /^tts:[^#?]*\?([^#]*)/.exec(ttsUri);
if (m === null) { return null; }
- const searchParameters = {};
- for (const group of m[1].split('&')) {
- const sep = group.indexOf('=');
- if (sep < 0) { continue; }
- searchParameters[decodeURIComponent(group.substring(0, sep))] = decodeURIComponent(group.substring(sep + 1));
- }
-
- if (!searchParameters.text) { return null; }
+ const searchParameters = new URLSearchParams(m[1]);
+ const text = searchParameters.get('text');
+ let voice = searchParameters.get('voice');
+ if (text === null || voice === null) { return null; }
- const voice = audioGetTextToSpeechVoice(searchParameters.voice);
+ voice = audioGetTextToSpeechVoice(voice);
if (voice === null) { return null; }
- return new TextToSpeechAudio(searchParameters.text, voice);
+ return new TextToSpeechAudio(text, voice);
}
}
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index aa10bbaf..db3835cf 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -158,7 +158,7 @@ class TextScanner {
onTouchEnd(e) {
if (
this.primaryTouchIdentifier === null ||
- TextScanner.getIndexOfTouch(e.changedTouches, this.primaryTouchIdentifier) < 0
+ TextScanner.getTouch(e.changedTouches, this.primaryTouchIdentifier) === null
) {
return;
}
@@ -181,13 +181,11 @@ class TextScanner {
return;
}
- const touches = e.changedTouches;
- const index = TextScanner.getIndexOfTouch(touches, this.primaryTouchIdentifier);
- if (index < 0) {
+ const primaryTouch = TextScanner.getTouch(e.changedTouches, this.primaryTouchIdentifier);
+ if (primaryTouch === null) {
return;
}
- const primaryTouch = touches[index];
this.searchAt(primaryTouch.clientX, primaryTouch.clientY, 'touchMove');
e.preventDefault(); // Disable scroll
@@ -356,13 +354,12 @@ class TextScanner {
}
}
- static getIndexOfTouch(touchList, identifier) {
- for (const i in touchList) {
- const t = touchList[i];
- if (t.identifier === identifier) {
- return i;
+ static getTouch(touchList, identifier) {
+ for (const touch of touchList) {
+ if (touch.identifier === identifier) {
+ return touch;
}
}
- return -1;
+ return null;
}
}