diff options
Diffstat (limited to 'ext/js/data')
-rw-r--r-- | ext/js/data/anki-note-builder.js | 11 | ||||
-rw-r--r-- | ext/js/data/options-util.js | 1 |
2 files changed, 11 insertions, 1 deletions
diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index 65740254..23dd648b 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -283,6 +283,7 @@ class AnkiNoteBuilder { let injectScreenshot = false; let injectClipboardImage = false; let injectClipboardText = false; + let injectSelectionText = false; const dictionaryMediaDetails = []; for (const requirement of requirements) { const {type} = requirement; @@ -291,6 +292,7 @@ class AnkiNoteBuilder { case 'screenshot': injectScreenshot = true; break; case 'clipboardImage': injectClipboardImage = true; break; case 'clipboardText': injectClipboardText = true; break; + case 'selectionText': injectSelectionText = true; break; case 'dictionaryMedia': { const {dictionary, path} = requirement; @@ -323,7 +325,8 @@ class AnkiNoteBuilder { } // Inject media - const {audioFileName, screenshotFileName, clipboardImageFileName, clipboardText, dictionaryMedia: dictionaryMediaArray, errors} = await yomichan.api.injectAnkiNoteMedia( + const selectionText = injectSelectionText ? this._getSelectionText() : null; + const injectedMedia = await yomichan.api.injectAnkiNoteMedia( timestamp, dictionaryEntryDetails, audioDetails, @@ -331,6 +334,7 @@ class AnkiNoteBuilder { clipboardDetails, dictionaryMediaDetails ); + const {audioFileName, screenshotFileName, clipboardImageFileName, clipboardText, dictionaryMedia: dictionaryMediaArray, errors} = injectedMedia; // Format results const dictionaryMedia = {}; @@ -348,8 +352,13 @@ class AnkiNoteBuilder { screenshot: (typeof screenshotFileName === 'string' ? {fileName: screenshotFileName} : null), clipboardImage: (typeof clipboardImageFileName === 'string' ? {fileName: clipboardImageFileName} : null), clipboardText: (typeof clipboardText === 'string' ? {text: clipboardText} : null), + selectionText: (typeof selectionText === 'string' ? {text: selectionText} : null), dictionaryMedia }; return {media, errors}; } + + _getSelectionText() { + return document.getSelection().toString(); + } } diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index baa727d2..3d36fc2e 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -854,6 +854,7 @@ class OptionsUtil { // Version 13 changes: // Handlebars templates updated to use formatGlossary. // Handlebars templates updated to use new media format. + // Added {selection-text} field marker. await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v13.handlebars'); return options; } |