summaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2019-09-23 17:35:36 -0700
committerAlex Yatskov <alex@foosoft.net>2019-09-23 17:35:36 -0700
commitf4b6527ed6ed1f0f4f5a63b94766b20f3b90e6ec (patch)
tree0d2f733c13597dd4067d3dc01e6da27f96bfe81b /ext/bg/js/api.js
parentcfc6363a01ee00e89866c54709006d6f55d093de (diff)
parentf5afe590ad0730a695614b32032b7ea70b46c7b0 (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js44
1 files changed, 28 insertions, 16 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index b8ef4362..474fe604 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -17,16 +17,23 @@
*/
-async function apiOptionsSet(options) {
- utilBackend().onOptionsUpdated(options);
+function apiOptionsGet(optionsContext) {
+ return utilBackend().getOptions(optionsContext);
}
-async function apiOptionsGet() {
- return utilBackend().options;
+function apiOptionsGetFull() {
+ return utilBackend().getFullOptions();
}
-async function apiTermsFind(text) {
- const options = utilBackend().options;
+async function apiOptionsSave(source) {
+ const backend = utilBackend();
+ const options = await apiOptionsGetFull();
+ await optionsSave(options);
+ backend.onOptionsUpdated(source);
+}
+
+async function apiTermsFind(text, optionsContext) {
+ const options = await apiOptionsGet(optionsContext);
const translator = utilBackend().translator;
const searcher = {
@@ -38,7 +45,8 @@ async function apiTermsFind(text) {
const {definitions, length} = await searcher(
text,
dictEnabledSet(options),
- options.scanning.alphanumeric
+ options.scanning.alphanumeric,
+ options
);
return {
@@ -47,14 +55,14 @@ async function apiTermsFind(text) {
};
}
-async function apiKanjiFind(text) {
- const options = utilBackend().options;
+async function apiKanjiFind(text, optionsContext) {
+ const options = await apiOptionsGet(optionsContext);
const definitions = await utilBackend().translator.findKanji(text, dictEnabledSet(options));
return definitions.slice(0, options.general.maxResults);
}
-async function apiDefinitionAdd(definition, mode, context) {
- const options = utilBackend().options;
+async function apiDefinitionAdd(definition, mode, context, optionsContext) {
+ const options = await apiOptionsGet(optionsContext);
if (mode !== 'kanji') {
await audioInject(
@@ -76,14 +84,15 @@ async function apiDefinitionAdd(definition, mode, context) {
return utilBackend().anki.addNote(note);
}
-async function apiDefinitionsAddable(definitions, modes) {
+async function apiDefinitionsAddable(definitions, modes, optionsContext) {
+ const options = await apiOptionsGet(optionsContext);
const states = [];
try {
const notes = [];
for (const definition of definitions) {
for (const mode of modes) {
- const note = await dictNoteFormat(definition, mode, utilBackend().options);
+ const note = await dictNoteFormat(definition, mode, options);
notes.push(note);
}
}
@@ -131,10 +140,13 @@ async function apiCommandExec(command) {
},
toggle: async () => {
- const options = utilBackend().options;
+ const optionsContext = {
+ depth: 0,
+ url: window.location.href
+ };
+ const options = await apiOptionsGet(optionsContext);
options.general.enable = !options.general.enable;
- await optionsSave(options);
- await apiOptionsSet(options);
+ await apiOptionsSave('popup');
}
};