From a567ef360523e71040348fdded761c6d71a6d4d5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 18 Jul 2016 08:08:31 -0700 Subject: [PATCH] Pronounce => Play Audio --- ext/bg/js/templates.js | 4 ++-- ext/fg/img/{pronounce.png => play_audio.png} | Bin ext/fg/js/client.js | 10 +++++++--- ext/fg/js/frame.js | 8 ++++---- ext/manifest.json | 2 +- tmpl/term.html | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) rename ext/fg/img/{pronounce.png => play_audio.png} (100%) diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 11529eff..079389f2 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -104,11 +104,11 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial },"2":function(container,depth0,helpers,partials,data,blockParams,depths) { var helper, alias1=container.escapeExpression; - return " \n"; + + "/img/play_audio.png\">\n"; },"4":function(container,depth0,helpers,partials,data,blockParams,depths) { var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression, alias5=container.lambda; diff --git a/ext/fg/img/pronounce.png b/ext/fg/img/play_audio.png similarity index 100% rename from ext/fg/img/pronounce.png rename to ext/fg/img/play_audio.png diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index 1f77ed95..10e8a0ae 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -168,9 +168,13 @@ class Client { }); } - api_pronounce(index) { - const dfn = this.definitions[index]; - const url = `http://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kana=${dfn.reading}&kanji=${dfn.expression}`; + api_playAudio(index) { + const definition = this.definitions[index]; + + let url = `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=${definition.expression}`; + if (definition.reading) { + url += `&kana=${definition.reading}`; + } for (let key in this.audio) { this.audio[key].pause(); diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js index 9c4b9318..165a9795 100644 --- a/ext/fg/js/frame.js +++ b/ext/fg/js/frame.js @@ -36,12 +36,12 @@ function registerAddNoteLinks() { } } -function registerPronounceLinks() { - for (let link of [].slice.call(document.getElementsByClassName('action-pronounce'))) { +function registerAudioLinks() { + for (let link of [].slice.call(document.getElementsByClassName('action-play-audio'))) { link.addEventListener('click', (e) => { e.preventDefault(); const ds = e.currentTarget.dataset; - window.parent.postMessage({action: 'pronounce', params: ds.index}, '*'); + window.parent.postMessage({action: 'playAudio', params: ds.index}, '*'); }); } } @@ -49,7 +49,7 @@ function registerPronounceLinks() { function onDomContentLoaded() { registerKanjiLinks(); registerAddNoteLinks(); - registerPronounceLinks(); + registerAudioLinks(); } function onMessage(e) { diff --git a/ext/manifest.json b/ext/manifest.json index 0c315fa4..5234ed5d 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -24,7 +24,7 @@ "fg/img/add_kanji.png", "fg/img/add_vocab_kana.png", "fg/img/add_vocab_kanji.png", - "fg/img/pronounce.png", + "fg/img/play_audio.png", "fg/js/frame.js", "fg/ttf/kanji-stroke-orders.ttf", "fg/ttf/vl-gothic-regular.ttf" diff --git a/tmpl/term.html b/tmpl/term.html index 6296a2f3..1bb79375 100644 --- a/tmpl/term.html +++ b/tmpl/term.html @@ -2,7 +2,7 @@ {{#with options}}
{{#if enableAudioPlayback}} - + {{/if}} {{#if enableAnkiConnect}}