summaryrefslogtreecommitdiff
path: root/ext/bg/js/anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-27 18:10:59 -0400
committerGitHub <noreply@github.com>2020-04-27 18:10:59 -0400
commit0956634d61ef2b6202645ec4b502239573c2e743 (patch)
treee53dcf42db38c57d0e48cb0970574a3945951372 /ext/bg/js/anki.js
parent48c7010f4ea8daafd30e5650625c377affa0cecd (diff)
Add duplicateScope: 'deck' option (#476)
* Add duplicateScope: 'deck' option * Add option to control duplicate scope * Use duplicateScope for findNoteIds * Update location of quotes
Diffstat (limited to 'ext/bg/js/anki.js')
-rw-r--r--ext/bg/js/anki.js15
1 files changed, 7 insertions, 8 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js
index 38823431..0d38837c 100644
--- a/ext/bg/js/anki.js
+++ b/ext/bg/js/anki.js
@@ -87,15 +87,14 @@ class AnkiConnect {
return await this._invoke('storeMediaFile', {filename, data: dataBase64});
}
- async findNoteIds(notes) {
+ async findNoteIds(notes, duplicateScope) {
if (!this._enabled) { return []; }
await this._checkVersion();
- const actions = notes.map((note) => ({
- action: 'findNotes',
- params: {
- query: `deck:"${this._escapeQuery(note.deckName)}" ${this._fieldsToQuery(note.fields)}`
- }
- }));
+ const actions = notes.map((note) => {
+ let query = (duplicateScope === 'deck' ? `"deck:${this._escapeQuery(note.deckName)}" ` : '');
+ query += this._fieldsToQuery(note.fields);
+ return {action: 'findNotes', params: {query}};
+ });
return await this._invoke('multi', {actions});
}
@@ -132,6 +131,6 @@ class AnkiConnect {
}
const key = fieldNames[0];
- return `${key.toLowerCase()}:"${this._escapeQuery(fields[key])}"`;
+ return `"${key.toLowerCase()}:${this._escapeQuery(fields[key])}"`;
}
}