summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/anki.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js
index 021cb4c4..f7a24291 100644
--- a/ext/bg/js/anki.js
+++ b/ext/bg/js/anki.js
@@ -25,47 +25,74 @@
class AnkiConnect {
constructor(server) {
+ this._enabled = true;
this._server = server;
this._localVersion = 2;
this._remoteVersion = 0;
}
+ setServer(server) {
+ this._server = server;
+ }
+
+ getServer() {
+ return this._server;
+ }
+
+ setEnabled(enabled) {
+ this._enabled = enabled;
+ }
+
+ isEnabled() {
+ return this._enabled;
+ }
+
async addNote(note) {
+ if (!this._enabled) { return null; }
await this._checkVersion();
return await this._ankiInvoke('addNote', {note});
}
async canAddNotes(notes) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('canAddNotes', {notes});
}
async getDeckNames() {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('deckNames');
}
async getModelNames() {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('modelNames');
}
async getModelFieldNames(modelName) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('modelFieldNames', {modelName});
}
async guiBrowse(query) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
return await this._ankiInvoke('guiBrowse', {query});
}
async storeMediaFile(filename, dataBase64) {
+ if (!this._enabled) {
+ return {result: null, error: 'AnkiConnect not enabled'};
+ }
await this._checkVersion();
return await this._ankiInvoke('storeMediaFile', {filename, data: dataBase64});
}
async findNoteIds(notes) {
+ if (!this._enabled) { return []; }
await this._checkVersion();
const actions = notes.map((note) => ({
action: 'findNotes',