summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/anki.js9
-rw-r--r--ext/bg/js/api.js2
-rw-r--r--ext/bg/js/backend.js20
-rw-r--r--ext/bg/js/context.js4
-rw-r--r--ext/bg/js/database.js2
-rw-r--r--ext/bg/js/deinflector.js2
-rw-r--r--ext/bg/js/dictionary.js2
-rw-r--r--ext/bg/js/handlebars.js2
-rw-r--r--ext/bg/js/search.js5
-rw-r--r--ext/bg/js/settings.js50
-rw-r--r--ext/bg/js/util.js7
11 files changed, 63 insertions, 42 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js
index f0ec4571..c327969f 100644
--- a/ext/bg/js/anki.js
+++ b/ext/bg/js/anki.js
@@ -17,6 +17,10 @@
*/
+/*
+ * AnkiConnect
+ */
+
class AnkiConnect {
constructor(server) {
this.server = server;
@@ -68,6 +72,11 @@ class AnkiConnect {
}
}
+
+/*
+ * AnkiNull
+ */
+
class AnkiNull {
async addNote(note) {
return null;
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 024ba75e..b55e306f 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index e8c9452c..97e5602a 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
@@ -77,7 +77,11 @@ class Backend {
const handlers = {
optionsGet: ({callback}) => {
- forward(optionsLoad(), callback);
+ forward(apiOptionsGet(), callback);
+ },
+
+ optionsSet: ({options, callback}) => {
+ forward(apiOptionsSet(options), callback);
},
kanjiFind: ({text, callback}) => {
@@ -88,10 +92,6 @@ class Backend {
forward(apiTermsFind(text), callback);
},
- templateRender: ({template, data, callback}) => {
- forward(apiTemplateRender(template, data), callback);
- },
-
definitionAdd: ({definition, mode, callback}) => {
forward(apiDefinitionAdd(definition, mode), callback);
},
@@ -102,6 +102,14 @@ class Backend {
noteView: ({noteId}) => {
forward(apiNoteView(noteId), callback);
+ },
+
+ templateRender: ({template, data, callback}) => {
+ forward(apiTemplateRender(template, data), callback);
+ },
+
+ commandExec: ({command, callback}) => {
+ forward(apiCommandExec(command), callback);
}
};
diff --git a/ext/bg/js/context.js b/ext/bg/js/context.js
index 77cb5166..689d6863 100644
--- a/ext/bg/js/context.js
+++ b/ext/bg/js/context.js
@@ -17,7 +17,7 @@
*/
-$(document).ready(() => {
+$(document).ready(utilAsync(() => {
$('#open-search').click(() => apiCommandExec('search'));
$('#open-options').click(() => apiCommandExec('options'));
$('#open-help').click(() => apiCommandExec('help'));
@@ -28,4 +28,4 @@ $(document).ready(() => {
toggle.bootstrapToggle();
toggle.change(() => apiCommandExec('toggle'));
});
-});
+}));
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index b38e00db..e00cb7a3 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
diff --git a/ext/bg/js/deinflector.js b/ext/bg/js/deinflector.js
index 8b67761b..0abde99d 100644
--- a/ext/bg/js/deinflector.js
+++ b/ext/bg/js/deinflector.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 6f9b30e4..c8d431b9 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js
index df98bef1..debb0690 100644
--- a/ext/bg/js/handlebars.js
+++ b/ext/bg/js/handlebars.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 87f50c32..54cda8ec 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
@@ -41,9 +41,8 @@ class DisplaySearch extends Display {
}
async onSearch(e) {
- e.preventDefault();
-
try {
+ e.preventDefault();
this.intro.slideUp();
const {length, definitions} = await apiTermsFind(this.query.val());
super.termsShow(definitions, await apiOptionsGet());
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index ce9e14a2..89b1581f 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
@@ -90,12 +90,12 @@ function formUpdateVisibility(options) {
}
}
-async function onFormOptionsChanged(e) {(async () => {
- if (!e.originalEvent && !e.isTrigger) {
- return;
- }
-
+async function onFormOptionsChanged(e) {
try {
+ if (!e.originalEvent && !e.isTrigger) {
+ return;
+ }
+
ankiErrorShow();
ankiSpinnerShow(true);
@@ -116,9 +116,9 @@ async function onFormOptionsChanged(e) {(async () => {
} finally {
ankiSpinnerShow(false);
}
-})();}
+}
-function onReady() {(async () => {
+async function onReady() {
const options = await optionsLoad();
$('#show-usage-guide').prop('checked', options.general.showGuide);
@@ -139,16 +139,16 @@ function onReady() {(async () => {
$('#scan-length').val(options.scanning.length);
$('#scan-modifier-key').val(options.scanning.modifier);
- $('#dict-purge').click(onDictionaryPurge);
- $('#dict-file').change(onDictionaryImport);
+ $('#dict-purge').click(utilAsync(onDictionaryPurge));
+ $('#dict-file').change(utilAsync(onDictionaryImport));
$('#anki-enable').prop('checked', options.anki.enable);
$('#card-tags').val(options.anki.tags.join(' '));
$('#generate-html-cards').prop('checked', options.anki.htmlCards);
$('#sentence-detection-extent').val(options.anki.sentenceExt);
$('#interface-server').val(options.anki.server);
- $('input, select').not('.anki-model').change(onFormOptionsChanged);
- $('.anki-model').change(onAnkiModelChanged);
+ $('input, select').not('.anki-model').change(utilAsync(onFormOptionsChanged));
+ $('.anki-model').change(utilAsync(onAnkiModelChanged));
try {
await dictionaryGroupsPopulate(options);
@@ -163,9 +163,9 @@ function onReady() {(async () => {
}
formUpdateVisibility(options);
-})();}
+}
-$(document).ready(onReady);
+$(document).ready(utilAsync(onReady));
/*
@@ -237,7 +237,7 @@ async function dictionaryGroupsPopulate(options) {
});
}
-async function onDictionaryPurge(e) {(async () => {
+async function onDictionaryPurge(e) {
e.preventDefault();
const dictControls = $('#dict-importer, #dict-groups').hide();
@@ -261,9 +261,9 @@ async function onDictionaryPurge(e) {(async () => {
dictControls.show();
dictProgress.hide();
}
-})();}
+}
-function onDictionaryImport(e) {(async () => {
+async function onDictionaryImport(e) {
const dictFile = $('#dict-file');
const dictControls = $('#dict-importer').hide();
const dictProgress = $('#dict-import-progress').show();
@@ -291,7 +291,7 @@ function onDictionaryImport(e) {(async () => {
dictControls.show();
dictProgress.hide();
}
-})();}
+}
/*
@@ -398,7 +398,7 @@ async function ankiFieldsPopulate(element, options) {
container.append($(html));
}
- tab.find('.anki-field-value').change(onFormOptionsChanged);
+ tab.find('.anki-field-value').change(utilAsync(onFormOptionsChanged));
tab.find('.marker-link').click(onAnkiMarkerClicked);
}
@@ -408,12 +408,12 @@ function onAnkiMarkerClicked(e) {
$(link).closest('.input-group').find('.anki-field-value').val(`{${link.text}}`).trigger('change');
}
-function onAnkiModelChanged(e) {(async () => {
- if (!e.originalEvent) {
- return;
- }
-
+async function onAnkiModelChanged(e) {
try {
+ if (!e.originalEvent) {
+ return;
+ }
+
ankiErrorShow();
ankiSpinnerShow(true);
@@ -431,4 +431,4 @@ function onAnkiModelChanged(e) {(async () => {
} finally {
ankiSpinnerShow(false);
}
-})();}
+}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 9dc57950..11ec23eb 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Alex Yatskov <alex@foosoft.net>
+ * Copyright (C) 2016-2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* This program is free software: you can redistribute it and/or modify
@@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+function utilAsync(func) {
+ return function(...args) {
+ func.apply(this, args);
+ };
+}
function utilBackend() {
return chrome.extension.getBackgroundPage().yomichan_backend;