diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-06 20:49:12 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-06 21:23:35 -0400 |
commit | 35ca0f35dd2cfea3223e5a38d5465002dd54993b (patch) | |
tree | 5ec6e1224fbfca90465c1729e83bf9ea4c1cc043 | |
parent | a74cdbff1dbfad48ae18cc101645b7a2b9ec8817 (diff) |
Create common function for utilBackend().options
-rw-r--r-- | ext/bg/js/api.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index b8ef4362..7126cab7 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -21,12 +21,16 @@ async function apiOptionsSet(options) { utilBackend().onOptionsUpdated(options); } -async function apiOptionsGet() { +function apiOptionsGetSync() { return utilBackend().options; } +async function apiOptionsGet() { + return apiOptionsGetSync(); +} + async function apiTermsFind(text) { - const options = utilBackend().options; + const options = apiOptionsGetSync(); const translator = utilBackend().translator; const searcher = { @@ -48,13 +52,13 @@ async function apiTermsFind(text) { } async function apiKanjiFind(text) { - const options = utilBackend().options; + const options = apiOptionsGetSync(); 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; + const options = apiOptionsGetSync(); if (mode !== 'kanji') { await audioInject( @@ -83,7 +87,7 @@ async function apiDefinitionsAddable(definitions, modes) { 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, apiOptionsGetSync()); notes.push(note); } } @@ -131,7 +135,7 @@ async function apiCommandExec(command) { }, toggle: async () => { - const options = utilBackend().options; + const options = apiOptionsGetSync(); options.general.enable = !options.general.enable; await optionsSave(options); await apiOptionsSet(options); |