aboutsummaryrefslogtreecommitdiff
path: root/ext/js/settings
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-14 15:53:35 -0500
committerGitHub <noreply@github.com>2021-02-14 15:53:35 -0500
commit286534e648af350d24fbf3c7892a7ec81aaeb4bd (patch)
tree89d88e961c5a0a6f508c66789e30b9ba4a968e73 /ext/js/settings
parentefe8140f103179f50b610f182148b9427af99010 (diff)
Move api to yomichan object (#1392)
* Move cross frame API from API to Yomichan * Add API instance to Yomichan * Move api global to yomichan.api * Pass yomichan to API * Remove IIFE
Diffstat (limited to 'ext/js/settings')
-rw-r--r--ext/js/settings/anki-templates-controller.js5
-rw-r--r--ext/js/settings/backup-controller.js5
-rw-r--r--ext/js/settings/dictionary-controller.js5
-rw-r--r--ext/js/settings/dictionary-import-controller.js5
-rw-r--r--ext/js/settings/extension-keyboard-shortcuts-controller.js3
-rw-r--r--ext/js/settings/keyboard-shortcuts-controller.js3
-rw-r--r--ext/js/settings/main.js6
-rw-r--r--ext/js/settings/mecab-controller.js6
-rw-r--r--ext/js/settings/pitch-accents-preview-main.js2
-rw-r--r--ext/js/settings/popup-preview-frame-main.js4
-rw-r--r--ext/js/settings/popup-preview-frame.js5
-rw-r--r--ext/js/settings/popup-window-controller.js6
-rw-r--r--ext/js/settings/profile-controller.js3
-rw-r--r--ext/js/settings/scan-inputs-controller.js3
-rw-r--r--ext/js/settings/scan-inputs-simple-controller.js3
-rw-r--r--ext/js/settings/settings-controller.js13
-rw-r--r--ext/js/settings/settings-main.js6
17 files changed, 28 insertions, 55 deletions
diff --git a/ext/js/settings/anki-templates-controller.js b/ext/js/settings/anki-templates-controller.js
index 31bd1e92..8e3a1a70 100644
--- a/ext/js/settings/anki-templates-controller.js
+++ b/ext/js/settings/anki-templates-controller.js
@@ -17,7 +17,6 @@
/* global
* AnkiNoteBuilder
- * api
*/
class AnkiTemplatesController {
@@ -37,7 +36,7 @@ class AnkiTemplatesController {
}
async prepare() {
- this._defaultFieldTemplates = await api.getDefaultAnkiFieldTemplates();
+ this._defaultFieldTemplates = await yomichan.api.getDefaultAnkiFieldTemplates();
this._fieldTemplatesTextarea = document.querySelector('#anki-card-templates-textarea');
this._compileResultInfo = document.querySelector('#anki-card-templates-compile-result');
@@ -154,7 +153,7 @@ class AnkiTemplatesController {
async _getDefinition(text, optionsContext) {
if (this._cachedDefinitionText !== text) {
- const {definitions} = await api.termsFind(text, {}, optionsContext);
+ const {definitions} = await yomichan.api.termsFind(text, {}, optionsContext);
if (definitions.length === 0) { return null; }
this._cachedDefinitionValue = definitions[0];
diff --git a/ext/js/settings/backup-controller.js b/ext/js/settings/backup-controller.js
index 8837b927..117f2422 100644
--- a/ext/js/settings/backup-controller.js
+++ b/ext/js/settings/backup-controller.js
@@ -18,7 +18,6 @@
/* global
* DictionaryController
* OptionsUtil
- * api
*/
class BackupController {
@@ -85,8 +84,8 @@ class BackupController {
async _getSettingsExportData(date) {
const optionsFull = await this._settingsController.getOptionsFull();
- const environment = await api.getEnvironmentInfo();
- const fieldTemplatesDefault = await api.getDefaultAnkiFieldTemplates();
+ const environment = await yomichan.api.getEnvironmentInfo();
+ const fieldTemplatesDefault = await yomichan.api.getDefaultAnkiFieldTemplates();
const permissions = await this._settingsController.permissionsUtil.getAllPermissions();
// Format options
diff --git a/ext/js/settings/dictionary-controller.js b/ext/js/settings/dictionary-controller.js
index ea9f7503..78173202 100644
--- a/ext/js/settings/dictionary-controller.js
+++ b/ext/js/settings/dictionary-controller.js
@@ -18,7 +18,6 @@
/* global
* DictionaryDatabase
* ObjectPropertyAccessor
- * api
*/
class DictionaryEntry {
@@ -362,7 +361,7 @@ class DictionaryController {
const token = this._databaseStateToken;
const dictionaryTitles = this._dictionaries.map(({title}) => title);
- const {counts, total} = await api.getDictionaryCounts(dictionaryTitles, true);
+ const {counts, total} = await yomichan.api.getDictionaryCounts(dictionaryTitles, true);
if (this._databaseStateToken !== token) { return; }
for (let i = 0, ii = Math.min(counts.length, this._dictionaryEntries.length); i < ii; ++i) {
@@ -499,7 +498,7 @@ class DictionaryController {
const dictionaryDatabase = await this._getPreparedDictionaryDatabase();
try {
await dictionaryDatabase.deleteDictionary(dictionaryTitle, {rate: 1000}, onProgress);
- api.triggerDatabaseUpdated('dictionary', 'delete');
+ yomichan.api.triggerDatabaseUpdated('dictionary', 'delete');
} finally {
dictionaryDatabase.close();
}
diff --git a/ext/js/settings/dictionary-import-controller.js b/ext/js/settings/dictionary-import-controller.js
index c4ad9e59..00eb7b95 100644
--- a/ext/js/settings/dictionary-import-controller.js
+++ b/ext/js/settings/dictionary-import-controller.js
@@ -19,7 +19,6 @@
* DictionaryDatabase
* DictionaryImporter
* ObjectPropertyAccessor
- * api
*/
class DictionaryImportController {
@@ -102,7 +101,7 @@ class DictionaryImportController {
this._setSpinnerVisible(true);
if (purgeNotification !== null) { purgeNotification.hidden = false; }
- await api.purgeDatabase();
+ await yomichan.api.purgeDatabase();
const errors = await this._clearDictionarySettings();
if (errors.length > 0) {
@@ -197,7 +196,7 @@ class DictionaryImportController {
const dictionaryImporter = new DictionaryImporter();
const archiveContent = await this._readFile(file);
const {result, errors} = await dictionaryImporter.importDictionary(dictionaryDatabase, archiveContent, importDetails, onProgress);
- api.triggerDatabaseUpdated('dictionary', 'import');
+ yomichan.api.triggerDatabaseUpdated('dictionary', 'import');
const errors2 = await this._addDictionarySettings(result.sequenced, result.title);
if (errors.length > 0) {
diff --git a/ext/js/settings/extension-keyboard-shortcuts-controller.js b/ext/js/settings/extension-keyboard-shortcuts-controller.js
index 9c930703..032f9dcc 100644
--- a/ext/js/settings/extension-keyboard-shortcuts-controller.js
+++ b/ext/js/settings/extension-keyboard-shortcuts-controller.js
@@ -18,7 +18,6 @@
/* global
* HotkeyUtil
* KeyboardMouseInputField
- * api
*/
class ExtensionKeyboardShortcutController {
@@ -53,7 +52,7 @@ class ExtensionKeyboardShortcutController {
this._clearButton.addEventListener('click', this._onClearClick.bind(this));
}
- const {platform: {os}} = await api.getEnvironmentInfo();
+ const {platform: {os}} = await yomichan.api.getEnvironmentInfo();
this._os = os;
this._hotkeyUtil.os = os;
diff --git a/ext/js/settings/keyboard-shortcuts-controller.js b/ext/js/settings/keyboard-shortcuts-controller.js
index 0dcfa2ee..99b16f06 100644
--- a/ext/js/settings/keyboard-shortcuts-controller.js
+++ b/ext/js/settings/keyboard-shortcuts-controller.js
@@ -17,7 +17,6 @@
/* global
* KeyboardMouseInputField
- * api
*/
class KeyboardShortcutController {
@@ -38,7 +37,7 @@ class KeyboardShortcutController {
}
async prepare() {
- const {platform: {os}} = await api.getEnvironmentInfo();
+ const {platform: {os}} = await yomichan.api.getEnvironmentInfo();
this._os = os;
this._addButton = document.querySelector('#hotkey-list-add');
diff --git a/ext/js/settings/main.js b/ext/js/settings/main.js
index 0707ea3c..51cd5f27 100644
--- a/ext/js/settings/main.js
+++ b/ext/js/settings/main.js
@@ -31,7 +31,6 @@
* ScanInputsSimpleController
* SettingsController
* StorageController
- * api
*/
function showExtensionInformation() {
@@ -43,7 +42,7 @@ function showExtensionInformation() {
}
async function setupEnvironmentInfo() {
- const {browser, platform} = await api.getEnvironmentInfo();
+ const {browser, platform} = await yomichan.api.getEnvironmentInfo();
document.documentElement.dataset.browser = browser;
document.documentElement.dataset.operatingSystem = platform.os;
}
@@ -51,13 +50,12 @@ async function setupEnvironmentInfo() {
(async () => {
try {
- api.prepare();
await yomichan.prepare();
setupEnvironmentInfo();
showExtensionInformation();
- const optionsFull = await api.optionsGetFull();
+ const optionsFull = await yomichan.api.optionsGetFull();
const modalController = new ModalController();
modalController.prepare();
diff --git a/ext/js/settings/mecab-controller.js b/ext/js/settings/mecab-controller.js
index ff2a4a66..122f82f9 100644
--- a/ext/js/settings/mecab-controller.js
+++ b/ext/js/settings/mecab-controller.js
@@ -15,10 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/* global
- * api
- */
-
class MecabController {
constructor(settingsController) {
this._settingsController = settingsController;
@@ -49,7 +45,7 @@ class MecabController {
this._testButton.disabled = true;
this._resultsContainer.textContent = '';
this._resultsContainer.hidden = true;
- await api.testMecab();
+ await yomichan.api.testMecab();
this._setStatus('Connection was successful', false);
} catch (e) {
this._setStatus(e.message, true);
diff --git a/ext/js/settings/pitch-accents-preview-main.js b/ext/js/settings/pitch-accents-preview-main.js
index 7bc995a2..fe3bd36d 100644
--- a/ext/js/settings/pitch-accents-preview-main.js
+++ b/ext/js/settings/pitch-accents-preview-main.js
@@ -17,12 +17,10 @@
/* global
* DisplayGenerator
- * api
*/
(async () => {
try {
- api.prepare();
await yomichan.prepare();
const displayGenerator = new DisplayGenerator({
diff --git a/ext/js/settings/popup-preview-frame-main.js b/ext/js/settings/popup-preview-frame-main.js
index f61b26dc..a62e8d28 100644
--- a/ext/js/settings/popup-preview-frame-main.js
+++ b/ext/js/settings/popup-preview-frame-main.js
@@ -19,15 +19,13 @@
* HotkeyHandler
* PopupFactory
* PopupPreviewFrame
- * api
*/
(async () => {
try {
- api.prepare();
await yomichan.prepare();
- const {tabId, frameId} = await api.frameInformationGet();
+ const {tabId, frameId} = await yomichan.api.frameInformationGet();
const hotkeyHandler = new HotkeyHandler();
hotkeyHandler.prepare();
diff --git a/ext/js/settings/popup-preview-frame.js b/ext/js/settings/popup-preview-frame.js
index 56100fb3..638dd414 100644
--- a/ext/js/settings/popup-preview-frame.js
+++ b/ext/js/settings/popup-preview-frame.js
@@ -18,7 +18,6 @@
/* global
* Frontend
* TextSourceRange
- * api
* wanakana
*/
@@ -63,8 +62,8 @@ class PopupPreviewFrame {
this._exampleTextInput.addEventListener('input', this._onExampleTextInputInput.bind(this), false);
// Overwrite API functions
- this._apiOptionsGetOld = api.optionsGet.bind(api);
- api.optionsGet = this._apiOptionsGet.bind(this);
+ this._apiOptionsGetOld = yomichan.api.optionsGet.bind(yomichan.api);
+ yomichan.api.optionsGet = this._apiOptionsGet.bind(this);
// Overwrite frontend
this._frontend = new Frontend({
diff --git a/ext/js/settings/popup-window-controller.js b/ext/js/settings/popup-window-controller.js
index cc83db68..403c060c 100644
--- a/ext/js/settings/popup-window-controller.js
+++ b/ext/js/settings/popup-window-controller.js
@@ -15,10 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/* global
- * api
- */
-
class PopupWindowController {
prepare() {
const testLink = document.querySelector('#test-window-open-link');
@@ -33,6 +29,6 @@ class PopupWindowController {
}
async _testWindowOpen() {
- await api.getOrCreateSearchPopup({focus: true});
+ await yomichan.api.getOrCreateSearchPopup({focus: true});
}
}
diff --git a/ext/js/settings/profile-controller.js b/ext/js/settings/profile-controller.js
index 914fc679..3883e80a 100644
--- a/ext/js/settings/profile-controller.js
+++ b/ext/js/settings/profile-controller.js
@@ -17,7 +17,6 @@
/* global
* ProfileConditionsUI
- * api
*/
class ProfileController {
@@ -58,7 +57,7 @@ class ProfileController {
}
async prepare() {
- const {platform: {os}} = await api.getEnvironmentInfo();
+ const {platform: {os}} = await yomichan.api.getEnvironmentInfo();
this._profileConditionsUI.os = os;
this._profileActiveSelect = document.querySelector('#profile-active-select');
diff --git a/ext/js/settings/scan-inputs-controller.js b/ext/js/settings/scan-inputs-controller.js
index eb179c6a..79b2bdf4 100644
--- a/ext/js/settings/scan-inputs-controller.js
+++ b/ext/js/settings/scan-inputs-controller.js
@@ -17,7 +17,6 @@
/* global
* KeyboardMouseInputField
- * api
*/
class ScanInputsController {
@@ -31,7 +30,7 @@ class ScanInputsController {
}
async prepare() {
- const {platform: {os}} = await api.getEnvironmentInfo();
+ const {platform: {os}} = await yomichan.api.getEnvironmentInfo();
this._os = os;
this._container = document.querySelector('#scan-input-list');
diff --git a/ext/js/settings/scan-inputs-simple-controller.js b/ext/js/settings/scan-inputs-simple-controller.js
index 01f044c2..b011af5d 100644
--- a/ext/js/settings/scan-inputs-simple-controller.js
+++ b/ext/js/settings/scan-inputs-simple-controller.js
@@ -18,7 +18,6 @@
/* global
* HotkeyUtil
* ScanInputsController
- * api
*/
class ScanInputsSimpleController {
@@ -34,7 +33,7 @@ class ScanInputsSimpleController {
this._middleMouseButtonScan = document.querySelector('#middle-mouse-button-scan');
this._mainScanModifierKeyInput = document.querySelector('#main-scan-modifier-key');
- const {platform: {os}} = await api.getEnvironmentInfo();
+ const {platform: {os}} = await yomichan.api.getEnvironmentInfo();
this._hotkeyUtil.os = os;
this._mainScanModifierKeyInputHasOther = false;
diff --git a/ext/js/settings/settings-controller.js b/ext/js/settings/settings-controller.js
index 11a9435c..4a86470d 100644
--- a/ext/js/settings/settings-controller.js
+++ b/ext/js/settings/settings-controller.js
@@ -19,7 +19,6 @@
* HtmlTemplateCollection
* OptionsUtil
* PermissionsUtil
- * api
*/
class SettingsController extends EventDispatcher {
@@ -62,16 +61,16 @@ class SettingsController extends EventDispatcher {
async getOptions() {
const optionsContext = this.getOptionsContext();
- return await api.optionsGet(optionsContext);
+ return await yomichan.api.optionsGet(optionsContext);
}
async getOptionsFull() {
- return await api.optionsGetFull();
+ return await yomichan.api.optionsGetFull();
}
async setAllSettings(value) {
const profileIndex = value.profileCurrent;
- await api.setAllSettings(value, this._source);
+ await yomichan.api.setAllSettings(value, this._source);
this._setProfileIndex(profileIndex);
}
@@ -108,7 +107,7 @@ class SettingsController extends EventDispatcher {
}
async getDictionaryInfo() {
- return await api.getDictionaryInfo();
+ return await yomichan.api.getDictionaryInfo();
}
getOptionsContext() {
@@ -171,12 +170,12 @@ class SettingsController extends EventDispatcher {
async _getSettings(targets, extraFields) {
targets = this._setupTargets(targets, extraFields);
- return await api.getSettings(targets);
+ return await yomichan.api.getSettings(targets);
}
async _modifySettings(targets, extraFields) {
targets = this._setupTargets(targets, extraFields);
- return await api.modifySettings(targets, this._source);
+ return await yomichan.api.modifySettings(targets, this._source);
}
_onBeforeUnload(e) {
diff --git a/ext/js/settings/settings-main.js b/ext/js/settings/settings-main.js
index a7e6b7b0..a5bb642c 100644
--- a/ext/js/settings/settings-main.js
+++ b/ext/js/settings/settings-main.js
@@ -42,12 +42,11 @@
* StatusFooter
* StorageController
* TranslationTextReplacementsController
- * api
*/
async function setupEnvironmentInfo() {
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
- const {browser, platform} = await api.getEnvironmentInfo();
+ const {browser, platform} = await yomichan.api.getEnvironmentInfo();
document.documentElement.dataset.browser = browser;
document.documentElement.dataset.os = platform.os;
document.documentElement.dataset.manifestVersion = `${manifestVersion}`;
@@ -66,12 +65,11 @@ async function setupGenericSettingsController(genericSettingController) {
const statusFooter = new StatusFooter(document.querySelector('.status-footer-container'));
statusFooter.prepare();
- api.prepare();
await yomichan.prepare();
setupEnvironmentInfo();
- const optionsFull = await api.optionsGetFull();
+ const optionsFull = await yomichan.api.optionsGetFull();
const preparePromises = [];