Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Anki findNotes #2152

Merged
merged 2 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
]);
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions ext/js/comm/anki.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions ext/js/comm/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ class API {
return this._invoke('getTermFrequencies', {termReadingList, dictionaries});
}

findAnkiNotes(query) {
return this._invoke('findAnkiNotes', {query});
}

// Utilities

_createActionPort(timeout=5000) {
Expand Down