From fd00a5285651313ce96f7fd00078c4bc72c00eb2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 21 May 2022 15:28:44 -0400 Subject: Anki findNotes (#2152) * Add findNotes API * Add api.findAnkiNotes --- ext/js/comm/anki.js | 12 ++++++++++++ ext/js/comm/api.js | 4 ++++ 2 files changed, 16 insertions(+) (limited to 'ext/js/comm') diff --git a/ext/js/comm/anki.js b/ext/js/comm/anki.js index 6921caf5..83cb8221 100644 --- a/ext/js/comm/anki.js +++ b/ext/js/comm/anki.js @@ -120,6 +120,18 @@ class AnkiConnect { return await this._invoke('storeMediaFile', {filename: fileName, data: content}); } + /** + * Finds notes matching a query. + * @param {string} query Searches for notes matching a query. + * @returns {number[]} An array of note IDs. + * @see https://docs.ankiweb.net/searching.html + */ + async findNotes(query) { + if (!this._enabled) { return []; } + await this._checkVersion(); + return await this._invoke('findNotes', {query}); + } + async findNoteIds(notes) { if (!this._enabled) { return []; } await this._checkVersion(); diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js index f978e491..75a01dd5 100644 --- a/ext/js/comm/api.js +++ b/ext/js/comm/api.js @@ -172,6 +172,10 @@ class API { return this._invoke('getTermFrequencies', {termReadingList, dictionaries}); } + findAnkiNotes(query) { + return this._invoke('findAnkiNotes', {query}); + } + // Utilities _createActionPort(timeout=5000) { -- cgit v1.2.3