diff options
Diffstat (limited to 'ext/mixed/js')
| -rw-r--r-- | ext/mixed/js/api.js | 8 | ||||
| -rw-r--r-- | ext/mixed/js/display.js | 24 | 
2 files changed, 24 insertions, 8 deletions
| diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js index 7dc77fb6..d9569187 100644 --- a/ext/mixed/js/api.js +++ b/ext/mixed/js/api.js @@ -77,6 +77,14 @@ const api = (() => {              return this._invoke('kanjiFind', {text, optionsContext});          } +        addAnkiNote(note) { +            return this._invoke('addAnkiNote', {note}); +        } + +        getAnkiNoteInfo(notes, duplicateScope) { +            return this._invoke('getAnkiNoteInfo', {notes, duplicateScope}); +        } +          definitionAdd(definition, mode, context, ownerFrameId, optionsContext) {              return this._invoke('definitionAdd', {definition, mode, context, ownerFrameId, optionsContext});          } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 6fdab46b..7dd5920a 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -889,10 +889,15 @@ class Display extends EventDispatcher {      async _setContentTermsOrKanjiUpdateAdderButtons(token, isTerms, definitions) {          const modes = isTerms ? ['term-kanji', 'term-kana'] : ['kanji']; -        const states = await this._getDefinitionsAddable(definitions, modes); +        let states; +        try { +            states = await this._getDefinitionsAddable(definitions, modes); +        } catch (e) { +            return; +        }          if (this._setContentToken !== token) { return; } -        this._updateAdderButtons(states); +        this._updateAdderButtons(states, modes);      }      _setContentExtensionUnloaded() { @@ -953,19 +958,22 @@ class Display extends EventDispatcher {          this._navigationHeader.dataset.hasNext = `${!!next}`;      } -    _updateAdderButtons(states) { -        for (let i = 0; i < states.length; ++i) { +    _updateAdderButtons(states, modes) { +        for (let i = 0, ii = states.length; i < ii; ++i) { +            const infos = states[i];              let noteId = null; -            for (const [mode, info] of Object.entries(states[i])) { +            for (let j = 0, jj = infos.length; j < jj; ++j) { +                const {canAdd, noteIds} = infos[j]; +                const mode = modes[j];                  const button = this._adderButtonFind(i, mode);                  if (button === null) {                      continue;                  } -                if (!info.canAdd && noteId === null && info.noteId) { -                    noteId = info.noteId; +                if (Array.isArray(noteIds) && noteIds.length > 0) { +                    noteId = noteIds[0];                  } -                button.classList.toggle('disabled', !info.canAdd); +                button.classList.toggle('disabled', !canAdd);                  button.classList.remove('pending');              }              if (noteId !== null) { |