aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-05-21 15:28:44 -0400
committerGitHub <noreply@github.com>2022-05-21 15:28:44 -0400
commitfd00a5285651313ce96f7fd00078c4bc72c00eb2 (patch)
tree5d84f50cf1293e76844b48980f1308c93c611f0d /ext/js
parent10e9f7acb867194d5f79e6254b4e8695ea5a6002 (diff)
Anki findNotes (#2152)
* Add findNotes API * Add api.findAnkiNotes
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/background/backend.js7
-rw-r--r--ext/js/comm/anki.js12
-rw-r--r--ext/js/comm/api.js4
3 files changed, 22 insertions, 1 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 66f80351..b25b6033 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -129,7 +129,8 @@ class Backend {
['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}],
['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}],
['textHasJapaneseCharacters', {async: false, contentScript: true, handler: this._onApiTextHasJapaneseCharacters.bind(this)}],
- ['getTermFrequencies', {async: true, contentScript: true, handler: this._onApiGetTermFrequencies.bind(this)}]
+ ['getTermFrequencies', {async: true, contentScript: true, handler: this._onApiGetTermFrequencies.bind(this)}],
+ ['findAnkiNotes', {async: true, contentScript: true, handler: this._onApiFindAnkiNotes.bind(this)}]
]);
this._messageHandlersWithProgress = new Map([
]);
@@ -752,6 +753,10 @@ class Backend {
return await this._translator.getTermFrequencies(termReadingList, dictionaries);
}
+ async _onApiFindAnkiNotes({query}) {
+ return await this._anki.findNotes(query);
+ }
+
// Command handlers
async _onCommandOpenSearchPage(params) {
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) {