aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-14 22:42:11 -0500
committerGitHub <noreply@github.com>2021-01-14 22:42:11 -0500
commit1dcfbf6ba6516d05f756d26bf84049d94776ab14 (patch)
tree538a1a4346a4f98ba366949eda33b4e981e58766 /ext/bg/js/backend.js
parentd9f5d21d15a8239ecf349d254606be2c8fa70d31 (diff)
Support suspending new anki cards (#1240)
* Add new option: anki.suspendNewCards * Update Anki APIs * Suspend card based on options * Add setting * Disable wrap for toggle property
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 6410b0fc..11a17381 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -97,6 +97,7 @@ class Backend {
['getAnkiNoteInfo', {async: true, contentScript: true, handler: this._onApiGetAnkiNoteInfo.bind(this)}],
['injectAnkiNoteMedia', {async: true, contentScript: true, handler: this._onApiInjectAnkiNoteMedia.bind(this)}],
['noteView', {async: true, contentScript: true, handler: this._onApiNoteView.bind(this)}],
+ ['suspendAnkiCardsForNote', {async: true, contentScript: true, handler: this._onApiSuspendAnkiCardsForNote.bind(this)}],
['commandExec', {async: false, contentScript: true, handler: this._onApiCommandExec.bind(this)}],
['getDefinitionAudioInfo', {async: true, contentScript: true, handler: this._onApiGetDefinitionAudioInfo.bind(this)}],
['downloadDefinitionAudio', {async: true, contentScript: true, handler: this._onApiDownloadDefinitionAudio.bind(this)}],
@@ -495,6 +496,16 @@ class Backend {
return await this._anki.guiBrowseNote(noteId);
}
+ async _onApiSuspendAnkiCardsForNote({noteId}) {
+ const cardIds = await this._anki.findCardsForNote(noteId);
+ const count = cardIds.length;
+ if (count > 0) {
+ const okay = await this._anki.suspendCards(cardIds);
+ if (!okay) { return 0; }
+ }
+ return count;
+ }
+
_onApiCommandExec({command, params}) {
return this._runCommand(command, params);
}