aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/settings')
-rw-r--r--ext/bg/js/settings/anki-templates.js21
-rw-r--r--ext/bg/js/settings/anki.js8
-rw-r--r--ext/bg/js/settings/backup.js10
-rw-r--r--ext/bg/js/settings/dictionaries.js24
-rw-r--r--ext/bg/js/settings/main.js10
-rw-r--r--ext/bg/js/settings/popup-preview-frame-main.js4
-rw-r--r--ext/bg/js/settings/popup-preview-frame.js9
-rw-r--r--ext/bg/js/settings/profiles.js6
-rw-r--r--ext/bg/js/settings/storage.js4
9 files changed, 40 insertions, 56 deletions
diff --git a/ext/bg/js/settings/anki-templates.js b/ext/bg/js/settings/anki-templates.js
index d5b6e677..0dadb433 100644
--- a/ext/bg/js/settings/anki-templates.js
+++ b/ext/bg/js/settings/anki-templates.js
@@ -19,10 +19,7 @@
* AnkiNoteBuilder
* ankiGetFieldMarkers
* ankiGetFieldMarkersHtml
- * apiGetDefaultAnkiFieldTemplates
- * apiOptionsGet
- * apiTemplateRender
- * apiTermsFind
+ * api
* getOptionsContext
* getOptionsMutable
* settingsSaveOptions
@@ -38,7 +35,7 @@ async function onAnkiFieldTemplatesResetConfirm(e) {
$('#field-template-reset-modal').modal('hide');
- const value = await apiGetDefaultAnkiFieldTemplates();
+ const value = await api.getDefaultAnkiFieldTemplates();
const element = document.querySelector('#field-templates');
element.value = value;
@@ -65,9 +62,9 @@ function ankiTemplatesInitialize() {
async function ankiTemplatesUpdateValue() {
const optionsContext = getOptionsContext();
- const options = await apiOptionsGet(optionsContext);
+ const options = await api.optionsGet(optionsContext);
let templates = options.anki.fieldTemplates;
- if (typeof templates !== 'string') { templates = await apiGetDefaultAnkiFieldTemplates(); }
+ if (typeof templates !== 'string') { templates = await api.getDefaultAnkiFieldTemplates(); }
$('#field-templates').val(templates);
onAnkiTemplatesValidateCompile();
@@ -79,7 +76,7 @@ const ankiTemplatesValidateGetDefinition = (() => {
return async (text, optionsContext) => {
if (cachedText !== text) {
- const {definitions} = await apiTermsFind(text, {}, optionsContext);
+ const {definitions} = await api.termsFind(text, {}, optionsContext);
if (definitions.length === 0) { return null; }
cachedValue = definitions[0];
@@ -97,15 +94,15 @@ async function ankiTemplatesValidate(infoNode, field, mode, showSuccessResult, i
const optionsContext = getOptionsContext();
const definition = await ankiTemplatesValidateGetDefinition(text, optionsContext);
if (definition !== null) {
- const options = await apiOptionsGet(optionsContext);
+ const options = await api.optionsGet(optionsContext);
const context = {
document: {
title: document.title
}
};
let templates = options.anki.fieldTemplates;
- if (typeof templates !== 'string') { templates = await apiGetDefaultAnkiFieldTemplates(); }
- const ankiNoteBuilder = new AnkiNoteBuilder({renderTemplate: apiTemplateRender});
+ if (typeof templates !== 'string') { templates = await api.getDefaultAnkiFieldTemplates(); }
+ const ankiNoteBuilder = new AnkiNoteBuilder({renderTemplate: api.templateRender.bind(api)});
result = await ankiNoteBuilder.formatField(field, definition, mode, context, options, templates, exceptions);
}
} catch (e) {
@@ -125,7 +122,7 @@ async function ankiTemplatesValidate(infoNode, field, mode, showSuccessResult, i
async function onAnkiFieldTemplatesChanged(e) {
// Get value
let templates = e.currentTarget.value;
- if (templates === await apiGetDefaultAnkiFieldTemplates()) {
+ if (templates === await api.getDefaultAnkiFieldTemplates()) {
// Default
templates = null;
}
diff --git a/ext/bg/js/settings/anki.js b/ext/bg/js/settings/anki.js
index ff1277ed..ba83f994 100644
--- a/ext/bg/js/settings/anki.js
+++ b/ext/bg/js/settings/anki.js
@@ -16,9 +16,7 @@
*/
/* global
- * apiGetAnkiDeckNames
- * apiGetAnkiModelFieldNames
- * apiGetAnkiModelNames
+ * api
* getOptionsContext
* getOptionsMutable
* onFormOptionsChanged
@@ -107,7 +105,7 @@ async function _ankiDeckAndModelPopulate(options) {
const kanjiModel = {value: options.anki.kanji.model, selector: '#anki-kanji-model'};
try {
_ankiSpinnerShow(true);
- const [deckNames, modelNames] = await Promise.all([apiGetAnkiDeckNames(), apiGetAnkiModelNames()]);
+ const [deckNames, modelNames] = await Promise.all([api.getAnkiDeckNames(), api.getAnkiModelNames()]);
deckNames.sort();
modelNames.sort();
termsDeck.values = deckNames;
@@ -180,7 +178,7 @@ async function _onAnkiModelChanged(e) {
let fieldNames;
try {
const modelName = node.value;
- fieldNames = await apiGetAnkiModelFieldNames(modelName);
+ fieldNames = await api.getAnkiModelFieldNames(modelName);
_ankiSetError(null);
} catch (error) {
_ankiSetError(error);
diff --git a/ext/bg/js/settings/backup.js b/ext/bg/js/settings/backup.js
index faf4e592..5eb55502 100644
--- a/ext/bg/js/settings/backup.js
+++ b/ext/bg/js/settings/backup.js
@@ -16,9 +16,7 @@
*/
/* global
- * apiGetDefaultAnkiFieldTemplates
- * apiGetEnvironmentInfo
- * apiOptionsGetFull
+ * api
* optionsGetDefault
* optionsUpdateVersion
* utilBackend
@@ -51,9 +49,9 @@ function _getSettingsExportDateString(date, dateSeparator, dateTimeSeparator, ti
}
async function _getSettingsExportData(date) {
- const optionsFull = await apiOptionsGetFull();
- const environment = await apiGetEnvironmentInfo();
- const fieldTemplatesDefault = await apiGetDefaultAnkiFieldTemplates();
+ const optionsFull = await api.optionsGetFull();
+ const environment = await api.getEnvironmentInfo();
+ const fieldTemplatesDefault = await api.getDefaultAnkiFieldTemplates();
// Format options
for (const {options} of optionsFull.profiles) {
diff --git a/ext/bg/js/settings/dictionaries.js b/ext/bg/js/settings/dictionaries.js
index 632c01ea..4d307f0f 100644
--- a/ext/bg/js/settings/dictionaries.js
+++ b/ext/bg/js/settings/dictionaries.js
@@ -17,13 +17,7 @@
/* global
* PageExitPrevention
- * apiDeleteDictionary
- * apiGetDictionaryCounts
- * apiGetDictionaryInfo
- * apiImportDictionaryArchive
- * apiOptionsGet
- * apiOptionsGetFull
- * apiPurgeDatabase
+ * api
* getOptionsContext
* getOptionsFullMutable
* getOptionsMutable
@@ -312,7 +306,7 @@ class SettingsDictionaryEntryUI {
progressBar.style.width = `${percent}%`;
};
- await apiDeleteDictionary(this.dictionaryInfo.title, onProgress);
+ await api.deleteDictionary(this.dictionaryInfo.title, onProgress);
} catch (e) {
dictionaryErrorsShow([e]);
} finally {
@@ -423,7 +417,7 @@ async function onDictionaryOptionsChanged() {
dictionaryUI.setOptionsDictionaries(options.dictionaries);
- const optionsFull = await apiOptionsGetFull();
+ const optionsFull = await api.optionsGetFull();
document.querySelector('#database-enable-prefix-wildcard-searches').checked = optionsFull.global.database.prefixWildcardsSupported;
await updateMainDictionarySelectValue();
@@ -431,7 +425,7 @@ async function onDictionaryOptionsChanged() {
async function onDatabaseUpdated() {
try {
- const dictionaries = await apiGetDictionaryInfo();
+ const dictionaries = await api.getDictionaryInfo();
dictionaryUI.setDictionaries(dictionaries);
document.querySelector('#dict-warning').hidden = (dictionaries.length > 0);
@@ -439,7 +433,7 @@ async function onDatabaseUpdated() {
updateMainDictionarySelectOptions(dictionaries);
await updateMainDictionarySelectValue();
- const {counts, total} = await apiGetDictionaryCounts(dictionaries.map((v) => v.title), true);
+ const {counts, total} = await api.getDictionaryCounts(dictionaries.map((v) => v.title), true);
dictionaryUI.setCounts(counts, total);
} catch (e) {
dictionaryErrorsShow([e]);
@@ -468,7 +462,7 @@ function updateMainDictionarySelectOptions(dictionaries) {
async function updateMainDictionarySelectValue() {
const optionsContext = getOptionsContext();
- const options = await apiOptionsGet(optionsContext);
+ const options = await api.optionsGet(optionsContext);
const value = options.general.mainDictionary;
@@ -618,7 +612,7 @@ async function onDictionaryPurge(e) {
dictionaryErrorsShow(null);
dictionarySpinnerShow(true);
- await apiPurgeDatabase();
+ await api.purgeDatabase();
for (const {options} of toIterable((await getOptionsFullMutable()).profiles)) {
options.dictionaries = utilBackgroundIsolate({});
options.general.mainDictionary = '';
@@ -666,7 +660,7 @@ async function onDictionaryImport(e) {
}
};
- const optionsFull = await apiOptionsGetFull();
+ const optionsFull = await api.optionsGetFull();
const importDetails = {
prefixWildcardsSupported: optionsFull.global.database.prefixWildcardsSupported
@@ -680,7 +674,7 @@ async function onDictionaryImport(e) {
}
const archiveContent = await dictReadFile(files[i]);
- const {result, errors} = await apiImportDictionaryArchive(archiveContent, importDetails, updateProgress);
+ const {result, errors} = await api.importDictionaryArchive(archiveContent, importDetails, updateProgress);
for (const {options} of toIterable((await getOptionsFullMutable()).profiles)) {
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
dictionaryOptions.enabled = true;
diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js
index 61395b1c..94f7f8f5 100644
--- a/ext/bg/js/settings/main.js
+++ b/ext/bg/js/settings/main.js
@@ -21,9 +21,7 @@
* ankiInitialize
* ankiTemplatesInitialize
* ankiTemplatesUpdateValue
- * apiForwardLogsToBackend
- * apiGetEnvironmentInfo
- * apiOptionsSave
+ * api
* appearanceInitialize
* audioSettingsInitialize
* backupInitialize
@@ -265,7 +263,7 @@ function settingsGetSource() {
async function settingsSaveOptions() {
const source = await settingsGetSource();
- await apiOptionsSave(source);
+ await api.optionsSave(source);
}
async function onOptionsUpdated({source}) {
@@ -290,7 +288,7 @@ async function settingsPopulateModifierKeys() {
const scanModifierKeySelect = document.querySelector('#scan-modifier-key');
scanModifierKeySelect.textContent = '';
- const environment = await apiGetEnvironmentInfo();
+ const environment = await api.getEnvironmentInfo();
const modifierKeys = [
{value: 'none', name: 'None'},
...environment.modifiers.keys
@@ -305,7 +303,7 @@ async function settingsPopulateModifierKeys() {
async function onReady() {
- apiForwardLogsToBackend();
+ api.forwardLogsToBackend();
await yomichan.prepare();
showExtensionInformation();
diff --git a/ext/bg/js/settings/popup-preview-frame-main.js b/ext/bg/js/settings/popup-preview-frame-main.js
index 8228125f..a362efa5 100644
--- a/ext/bg/js/settings/popup-preview-frame-main.js
+++ b/ext/bg/js/settings/popup-preview-frame-main.js
@@ -17,10 +17,10 @@
/* global
* SettingsPopupPreview
- * apiForwardLogsToBackend
+ * api
*/
(() => {
- apiForwardLogsToBackend();
+ api.forwardLogsToBackend();
new SettingsPopupPreview();
})();
diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js
index 8901a0c4..bd9357e9 100644
--- a/ext/bg/js/settings/popup-preview-frame.js
+++ b/ext/bg/js/settings/popup-preview-frame.js
@@ -20,14 +20,13 @@
* Popup
* PopupFactory
* TextSourceRange
- * apiFrameInformationGet
- * apiOptionsGet
+ * api
*/
class SettingsPopupPreview {
constructor() {
this.frontend = null;
- this.apiOptionsGetOld = apiOptionsGet;
+ this.apiOptionsGetOld = api.optionsGet.bind(api);
this.popup = null;
this.popupSetCustomOuterCssOld = null;
this.popupShown = false;
@@ -54,10 +53,10 @@ class SettingsPopupPreview {
document.querySelector('#theme-dark-checkbox').addEventListener('change', this.onThemeDarkCheckboxChanged.bind(this), false);
// Overwrite API functions
- window.apiOptionsGet = this.apiOptionsGet.bind(this);
+ api.optionsGet = this.apiOptionsGet.bind(this);
// Overwrite frontend
- const {frameId} = await apiFrameInformationGet();
+ const {frameId} = await api.frameInformationGet();
const popupFactory = new PopupFactory(frameId);
await popupFactory.prepare();
diff --git a/ext/bg/js/settings/profiles.js b/ext/bg/js/settings/profiles.js
index bdf5a13d..e32d5525 100644
--- a/ext/bg/js/settings/profiles.js
+++ b/ext/bg/js/settings/profiles.js
@@ -17,7 +17,7 @@
/* global
* ConditionsUI
- * apiOptionsGetFull
+ * api
* conditionsClearCaches
* formWrite
* getOptionsFullMutable
@@ -215,7 +215,7 @@ async function onProfileRemove(e) {
return await onProfileRemoveConfirm();
}
- const optionsFull = await apiOptionsGetFull();
+ const optionsFull = await api.optionsGetFull();
if (optionsFull.profiles.length <= 1) {
return;
}
@@ -278,7 +278,7 @@ async function onProfileMove(offset) {
}
async function onProfileCopy() {
- const optionsFull = await apiOptionsGetFull();
+ const optionsFull = await api.optionsGetFull();
if (optionsFull.profiles.length <= 1) {
return;
}
diff --git a/ext/bg/js/settings/storage.js b/ext/bg/js/settings/storage.js
index d754a109..73c93fa1 100644
--- a/ext/bg/js/settings/storage.js
+++ b/ext/bg/js/settings/storage.js
@@ -16,7 +16,7 @@
*/
/* global
- * apiGetEnvironmentInfo
+ * api
*/
function storageBytesToLabeledString(size) {
@@ -52,7 +52,7 @@ async function isStoragePeristent() {
async function storageInfoInitialize() {
storagePersistInitialize();
- const {browser, platform} = await apiGetEnvironmentInfo();
+ const {browser, platform} = await api.getEnvironmentInfo();
document.documentElement.dataset.browser = browser;
document.documentElement.dataset.operatingSystem = platform.os;