aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-09 11:54:40 -0400
committerGitHub <noreply@github.com>2020-09-09 11:54:40 -0400
commit2aa86cc5f8cda022076f7fa047f17fdcca4a0f5e (patch)
treed89d3776d46e76fc818b3ac4ba420d38c024002e /ext/bg/js/anki.js
parentb687870a55eae43a71ea3adc41be0ab341a8721f (diff)
Anki API refactor (#790)
* Add function guiBrowseNote * Assign default server as null * Use get/set properties for server/enabled * Refactor option values * Refactor createNote/Data functions to not use options format directly * Use createNote for testing * Add errors
Diffstat (limited to 'ext/bg/js/anki.js')
-rw-r--r--ext/bg/js/anki.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js
index b1e1f7b4..182b4ded 100644
--- a/ext/bg/js/anki.js
+++ b/ext/bg/js/anki.js
@@ -16,30 +16,30 @@
*/
class AnkiConnect {
- constructor(server) {
+ constructor() {
this._enabled = false;
- this._server = server;
+ this._server = null;
this._localVersion = 2;
this._remoteVersion = 0;
this._versionCheckPromise = null;
}
- setServer(server) {
- this._server = server;
- }
-
- getServer() {
+ get server() {
return this._server;
}
- setEnabled(enabled) {
- this._enabled = enabled;
+ set server(value) {
+ this._server = value;
}
- isEnabled() {
+ get enabled() {
return this._enabled;
}
+ set enabled(value) {
+ this._enabled = value;
+ }
+
async addNote(note) {
if (!this._enabled) { return null; }
await this._checkVersion();
@@ -76,6 +76,10 @@ class AnkiConnect {
return await this._invoke('guiBrowse', {query});
}
+ async guiBrowseNote(noteId) {
+ return await this.guiBrowse(`nid:${noteId}`);
+ }
+
async storeMediaFile(fileName, dataBase64) {
if (!this._enabled) {
throw new Error('AnkiConnect not enabled');