fix not being able to play audio for kana only terms
This commit is contained in:
parent
701c91ea66
commit
1a52a2d8d5
@ -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>
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user