summaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/anki-templates-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-04-04 16:22:35 -0400
committerGitHub <noreply@github.com>2021-04-04 16:22:35 -0400
commite14b52ef84be7feeab60167605fd10918a242cd3 (patch)
treeb9b124d9ed77806a7ad8b52c6e779da0f4844993 /ext/js/pages/settings/anki-templates-controller.js
parentb8bedd5185869edb33a7657fff323f812444eed0 (diff)
Update dictionary entry terminology (#1592)
* Update terminology * Update terminology in display.js * Update terminology in display-audio.js * Update terminology in text-scanner.js * Update terminology in backend.js * Update terminology in mecab.js * Update terminology in audio-downloader.js * Update terminology in translator-vm.js * Update terminology in dictionary-data-util.js * Update terminology in dictionary-database.js * Update terminology in japanese-util.js * Change/upgrade {expression} to {term} * Update terminology in test-japanese.js * Update terminology in test-database.js * Update terminology in anki-templates-controller.js * Update terminology in anki-note-builder.js * Update terminology in backend.js * Update terminology in text-scanner.js * Update terminology in display.js * Update terminology in display.js
Diffstat (limited to 'ext/js/pages/settings/anki-templates-controller.js')
-rw-r--r--ext/js/pages/settings/anki-templates-controller.js34
1 files changed, 20 insertions, 14 deletions
diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js
index 685c80d0..eab0681f 100644
--- a/ext/js/pages/settings/anki-templates-controller.js
+++ b/ext/js/pages/settings/anki-templates-controller.js
@@ -24,8 +24,8 @@ class AnkiTemplatesController {
this._settingsController = settingsController;
this._modalController = modalController;
this._ankiController = ankiController;
- this._cachedDefinitionValue = null;
- this._cachedDefinitionText = null;
+ this._cachedDictionaryEntryValue = null;
+ this._cachedDictionaryEntryText = null;
this._defaultFieldTemplates = null;
this._fieldTemplatesTextarea = null;
this._compileResultInfo = null;
@@ -114,7 +114,7 @@ class AnkiTemplatesController {
const field = this._renderFieldInput.value;
const infoNode = this._renderResult;
infoNode.hidden = true;
- this._cachedDefinitionText = null;
+ this._cachedDictionaryEntryText = null;
this._validate(infoNode, field, 'term-kanji', true, false);
}
@@ -132,15 +132,18 @@ class AnkiTemplatesController {
input.dispatchEvent(new Event('change'));
}
- async _getDefinition(text, optionsContext) {
- if (this._cachedDefinitionText !== text) {
- const {definitions} = await yomichan.api.termsFind(text, {}, optionsContext);
- if (definitions.length === 0) { return null; }
+ async _getDictionaryEntry(text, optionsContext) {
+ if (this._cachedDictionaryEntryText !== text) {
+ const {dictionaryEntries} = await yomichan.api.termsFind(text, {}, optionsContext);
+ if (dictionaryEntries.length === 0) { return null; }
- this._cachedDefinitionValue = definitions[0];
- this._cachedDefinitionText = text;
+ this._cachedDictionaryEntryValue = dictionaryEntries[0];
+ this._cachedDictionaryEntryText = text;
}
- return this._cachedDefinitionValue;
+ return {
+ dictionaryEntry: this._cachedDictionaryEntryValue,
+ text: this._cachedDictionaryEntryText
+ };
}
async _validate(infoNode, field, mode, showSuccessResult, invalidateInput) {
@@ -149,19 +152,22 @@ class AnkiTemplatesController {
let result = `No definition found for ${text}`;
try {
const optionsContext = this._settingsController.getOptionsContext();
- const definition = await this._getDefinition(text, optionsContext);
- if (definition !== null) {
+ const {dictionaryEntry, text: sentenceText} = await this._getDictionaryEntry(text, optionsContext);
+ if (dictionaryEntry !== null) {
const options = await this._settingsController.getOptions();
const context = {
url: window.location.href,
- sentence: {text: definition.rawSource, offset: 0},
+ sentence: {
+ text: sentenceText,
+ offset: 0
+ },
documentTitle: document.title
};
let template = options.anki.fieldTemplates;
if (typeof template !== 'string') { template = this._defaultFieldTemplates; }
const {general: {resultOutputMode, glossaryLayoutMode, compactTags}} = options;
const note = await this._ankiNoteBuilder.createNote({
- definition,
+ dictionaryEntry,
mode,
context,
template,