From 4f8c84d524365a32e6f4478597905bc553ad20c2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 13 Oct 2019 16:30:31 -0400 Subject: Fix Japanese voice ordering on Firefox for Android --- ext/bg/js/settings.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index debf9f2f..acc47f69 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -358,24 +358,28 @@ function updateTextToSpeechVoices() { select.val(select.attr('data-value')); } -function compareLanguageTags(a, b) { - if (a.substr(0, 3) === 'ja-') { - return (b.substr(0, 3) === 'ja-') ? 0 : -1; - } else { - return (b.substr(0, 3) === 'ja-') ? 1 : 0; - } +function languageTagIsJapanese(languageTag) { + return ( + languageTag.startsWith('ja-') || + languageTag.startsWith('jpn-') + ); } function textToSpeechVoiceCompare(a, b) { - const i = compareLanguageTags(a.voice.lang, b.voice.lang); - if (i !== 0) { return i; } + const aIsJapanese = languageTagIsJapanese(a.voice.lang); + const bIsJapanese = languageTagIsJapanese(b.voice.lang); + if (aIsJapanese) { + if (!bIsJapanese) { return -1; } + } else { + if (bIsJapanese) { return 1; } + } - if (a.voice.default) { - if (!b.voice.default) { - return -1; - } - } else if (b.voice.default) { - return 1; + const aIsDefault = a.voice.default; + const bIsDefault = b.voice.default; + if (aIsDefault) { + if (!bIsDefault) { return -1; } + } else { + if (bIsDefault) { return 1; } } if (a.index < b.index) { return -1; } -- cgit v1.2.3