diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-02-15 21:34:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-15 21:34:10 -0500 |
commit | 55f5182ca93778b74105c9c9097174d3138cad9e (patch) | |
tree | fd02c62d1de5accd2a4d1ddfa37cd5a568314ce5 /ext/js/display/display.js | |
parent | f2a387237bac02d93d1664ed7acb6a10108915b6 (diff) |
Audio popup menu primary card audio selection (#1406)
* Add card icon to audio menu items
* Update cache data format
* Create _getCacheItem
* Add _playAudioFromSource function
* Implement default card audio info
* Specify exact audio to download when an override is assigned
* Abstract using _getMenuItemSourceInfo
* Update downloadability check
* Update the main audio menu buttons to also assign the default source
Diffstat (limited to 'ext/js/display/display.js')
-rw-r--r-- | ext/js/display/display.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 6a2a3766..35f22718 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1452,7 +1452,7 @@ class Display extends EventDispatcher { let injectedMedia = null; if (injectMedia) { let errors2; - ({result: injectedMedia, errors: errors2} = await this._injectAnkiNoteMedia(definition, mode, options, fields)); + ({result: injectedMedia, errors: errors2} = await this._injectAnkiNoteMedia(definition, options, fields)); if (Array.isArray(errors)) { for (const error of errors2) { errors.push(deserializeError(error)); @@ -1479,20 +1479,35 @@ class Display extends EventDispatcher { }); } - async _injectAnkiNoteMedia(definition, mode, options, fields) { + async _injectAnkiNoteMedia(definition, options, fields) { const { anki: {screenshot: {format, quality}}, audio: {sources, customSourceUrl, customSourceType} } = options; const timestamp = Date.now(); + const definitionDetails = this._getDefinitionDetailsForNote(definition); - const audioDetails = (mode !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio') ? {sources, preferredAudioIndex: null, customSourceUrl, customSourceType} : null); + + let audioDetails = null; + if (definitionDetails.type !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio')) { + const primaryCardAudio = this._displayAudio.getPrimaryCardAudio(definitionDetails.expression, definitionDetails.reading); + let preferredAudioIndex = null; + let sources2 = sources; + if (primaryCardAudio !== null) { + sources2 = [primaryCardAudio.source]; + preferredAudioIndex = primaryCardAudio.index; + } + audioDetails = {sources: sources2, preferredAudioIndex, customSourceUrl, customSourceType}; + } + const screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {tabId: this._contentOriginTabId, frameId: this._contentOriginFrameId, format, quality} : null); + const clipboardDetails = { image: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'), text: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-text') }; + return await yomichan.api.injectAnkiNoteMedia( timestamp, definitionDetails, |