summaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-02-18 19:12:39 -0800
committerAlex Yatskov <alex@foosoft.net>2017-02-18 19:12:39 -0800
commit1a52a2d8d5f5ea5c106ae244ca1e5bbf0da22b6e (patch)
tree3240c34bb69e68f4d7b2a8b8d5362484ac71f6db /ext/fg
parent701c91ea66852631ccc6e7bfb23b49578646ff33 (diff)
fix not being able to play audio for kana only terms
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/frame.html1
-rw-r--r--ext/fg/js/frame.js27
2 files changed, 23 insertions, 5 deletions
diff --git a/ext/fg/frame.html b/ext/fg/frame.html
index b7e2b41a..bf7f0f7b 100644
--- a/ext/fg/frame.html
+++ b/ext/fg/frame.html
@@ -17,6 +17,7 @@
</div>
<script src="../lib/jquery-3.1.1.min.js"></script>
+ <script src="../lib/wanakana.min.js"></script>
<script src="js/util.js"></script>
<script src="js/frame.js"></script>
</body>
diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js
index ca0636f9..4f4a6378 100644
--- a/ext/fg/js/frame.js
+++ b/ext/fg/js/frame.js
@@ -164,11 +164,6 @@ class Frame {
}
playAudio(definition) {
- let url = `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=${encodeURIComponent(definition.expression)}`;
- if (definition.reading) {
- url += `&kana=${encodeURIComponent(definition.reading)}`;
- }
-
for (const key in this.audioCache) {
const audio = this.audioCache[key];
if (audio !== null) {
@@ -176,6 +171,28 @@ class Frame {
}
}
+ let kana = definition.reading;
+ let kanji = definition.expression;
+ if (!kana) {
+ if (!kanji) {
+ return;
+ }
+
+ if (wanakana.isHiragana(kanji)) {
+ kana = kanji;
+ kanji = null;
+ }
+ }
+
+ const params = [];
+ if (kanji) {
+ params.push(`kanji=${encodeURIComponent(kanji)}`);
+ }
+ if (kana) {
+ params.push(`kana=${encodeURIComponent(kana)}`);
+ }
+
+ const url = `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?${params.join('&')}`;
let audio = this.audioCache[url];
if (audio) {
audio.currentTime = 0;