diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-06 22:00:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 22:00:18 -0400 |
commit | 1088c17503cd6f52019a094ac19f68b0e12ba007 (patch) | |
tree | d96b446ff7895d532077f13b493429527acf766a /ext/js/data/anki-note-builder.js | |
parent | 8d1596cdf86976362dc9ed0678412b7b8b1ff20c (diff) |
Add support for injecting dictionary media into Anki cards (#1805)
Diffstat (limited to 'ext/js/data/anki-note-builder.js')
-rw-r--r-- | ext/js/data/anki-note-builder.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index c69d6741..65740254 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -283,7 +283,7 @@ class AnkiNoteBuilder { let injectScreenshot = false; let injectClipboardImage = false; let injectClipboardText = false; - const injectDictionaryMedia = []; + const dictionaryMediaDetails = []; for (const requirement of requirements) { const {type} = requirement; switch (type) { @@ -291,7 +291,12 @@ class AnkiNoteBuilder { case 'screenshot': injectScreenshot = true; break; case 'clipboardImage': injectClipboardImage = true; break; case 'clipboardText': injectClipboardText = true; break; - case 'dictionaryMedia': injectDictionaryMedia.push(requirement); break; + case 'dictionaryMedia': + { + const {dictionary, path} = requirement; + dictionaryMediaDetails.push({dictionary, path}); + } + break; } } @@ -318,17 +323,26 @@ class AnkiNoteBuilder { } // Inject media - // TODO : injectDictionaryMedia - const {result: {audioFileName, screenshotFileName, clipboardImageFileName, clipboardText}, errors} = await yomichan.api.injectAnkiNoteMedia( + const {audioFileName, screenshotFileName, clipboardImageFileName, clipboardText, dictionaryMedia: dictionaryMediaArray, errors} = await yomichan.api.injectAnkiNoteMedia( timestamp, dictionaryEntryDetails, audioDetails, screenshotDetails, - clipboardDetails + clipboardDetails, + dictionaryMediaDetails ); // Format results - const dictionaryMedia = {}; // TODO + const dictionaryMedia = {}; + for (const {dictionary, path, fileName} of dictionaryMediaArray) { + if (fileName === null) { continue; } + const dictionaryMedia2 = ( + Object.prototype.hasOwnProperty.call(dictionaryMedia, dictionary) ? + (dictionaryMedia[dictionary]) : + (dictionaryMedia[dictionary] = {}) + ); + dictionaryMedia2[path] = {fileName}; + } const media = { audio: (typeof audioFileName === 'string' ? {fileName: audioFileName} : null), screenshot: (typeof screenshotFileName === 'string' ? {fileName: screenshotFileName} : null), |