Merge branch 'dev'
This commit is contained in:
commit
a1ba96145d
@ -100,9 +100,11 @@ class Yomichan {
|
||||
note.deckName = this.options.anki.terms.deck;
|
||||
note.modelName = this.options.anki.terms.model;
|
||||
|
||||
if (definition.audio) {
|
||||
const audio = {
|
||||
kanji: definition.expression,
|
||||
kana: definition.reading,
|
||||
url: definition.audio.url,
|
||||
filename: definition.audio.filename,
|
||||
skipHash: '7e2c2f954ef6051373ba916f000168dc',
|
||||
fields: []
|
||||
};
|
||||
|
||||
@ -116,6 +118,7 @@ class Yomichan {
|
||||
note.audio = audio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const name in fields) {
|
||||
note.fields[name] = formatField(
|
||||
|
@ -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>
|
||||
|
@ -113,7 +113,16 @@ class Frame {
|
||||
const index = link.data('index');
|
||||
const mode = link.data('mode');
|
||||
|
||||
addDefinition(this.definitions[index], mode).then(success => {
|
||||
const definition = this.definitions[index];
|
||||
if (mode !== 'kanji') {
|
||||
const url = buildAudioUrl(definition);
|
||||
const filename = buildAudioFilename(definition);
|
||||
if (url && filename) {
|
||||
definition.audio = {url, filename};
|
||||
}
|
||||
}
|
||||
|
||||
addDefinition(definition, mode).then(success => {
|
||||
if (success) {
|
||||
const button = this.findAddNoteButton(index, mode);
|
||||
button.addClass('disabled');
|
||||
@ -164,11 +173,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 +180,11 @@ class Frame {
|
||||
}
|
||||
}
|
||||
|
||||
const url = buildAudioUrl(definition);
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
let audio = this.audioCache[url];
|
||||
if (audio) {
|
||||
audio.currentTime = 0;
|
||||
|
@ -166,3 +166,43 @@ function extractSentence(source, extent) {
|
||||
|
||||
return content.substring(startPos, endPos).trim();
|
||||
}
|
||||
|
||||
function buildAudioUrl(definition) {
|
||||
let kana = definition.reading;
|
||||
let kanji = definition.expression;
|
||||
|
||||
if (!kana && !kanji) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!kana && wanakana.isHiragana(kanji)) {
|
||||
kana = kanji;
|
||||
kanji = null;
|
||||
}
|
||||
|
||||
const params = [];
|
||||
if (kanji) {
|
||||
params.push(`kanji=${encodeURIComponent(kanji)}`);
|
||||
}
|
||||
if (kana) {
|
||||
params.push(`kana=${encodeURIComponent(kana)}`);
|
||||
}
|
||||
|
||||
return `https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?${params.join('&')}`;
|
||||
}
|
||||
|
||||
function buildAudioFilename(definition) {
|
||||
if (!definition.reading && !definition.expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let filename = 'yomichan';
|
||||
if (definition.reading) {
|
||||
filename += `_${definition.reading}`;
|
||||
}
|
||||
if (definition.expression) {
|
||||
filename += `_${definition.expression}`;
|
||||
}
|
||||
|
||||
return filename += '.mp3';
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Yomichan",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.14",
|
||||
|
||||
"description": "Japanese dictionary with Anki integration",
|
||||
"icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"},
|
||||
|
Loading…
Reference in New Issue
Block a user