Anki findNotes (#2152)

* Add findNotes API

* Add api.findAnkiNotes
This commit is contained in:
toasted-nutbread 2022-05-21 15:28:44 -04:00 committed by GitHub
parent 10e9f7acb8
commit fd00a52856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -129,7 +129,8 @@ class Backend {
['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}], ['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}],
['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}], ['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}],
['textHasJapaneseCharacters', {async: false, contentScript: true, handler: this._onApiTextHasJapaneseCharacters.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([ this._messageHandlersWithProgress = new Map([
]); ]);
@ -752,6 +753,10 @@ class Backend {
return await this._translator.getTermFrequencies(termReadingList, dictionaries); return await this._translator.getTermFrequencies(termReadingList, dictionaries);
} }
async _onApiFindAnkiNotes({query}) {
return await this._anki.findNotes(query);
}
// Command handlers // Command handlers
async _onCommandOpenSearchPage(params) { async _onCommandOpenSearchPage(params) {

View File

@ -120,6 +120,18 @@ class AnkiConnect {
return await this._invoke('storeMediaFile', {filename: fileName, data: content}); 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) { async findNoteIds(notes) {
if (!this._enabled) { return []; } if (!this._enabled) { return []; }
await this._checkVersion(); await this._checkVersion();

View File

@ -172,6 +172,10 @@ class API {
return this._invoke('getTermFrequencies', {termReadingList, dictionaries}); return this._invoke('getTermFrequencies', {termReadingList, dictionaries});
} }
findAnkiNotes(query) {
return this._invoke('findAnkiNotes', {query});
}
// Utilities // Utilities
_createActionPort(timeout=5000) { _createActionPort(timeout=5000) {