aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-18 23:41:23 -0500
committerGitHub <noreply@github.com>2023-12-19 04:41:23 +0000
commit6b07b1e6e158f718fd30c44878a72c3b6ad83fa0 (patch)
tree0b95307e82416ff154c412b42c8eeaa033dac24f /ext/js/pages
parent1d268edcc3efce723954bcaa7dd376f0352c1a32 (diff)
IIFE updates (#384)
* Remove most IIFEs * Move IIFEs into functions * Don't await background-main
Diffstat (limited to 'ext/js/pages')
-rw-r--r--ext/js/pages/action-popup-main.js9
-rw-r--r--ext/js/pages/generic-page-main.js7
-rw-r--r--ext/js/pages/info-main.js116
-rw-r--r--ext/js/pages/permissions-main.js7
-rw-r--r--ext/js/pages/settings/popup-preview-frame-main.js7
-rw-r--r--ext/js/pages/settings/settings-main.js7
-rw-r--r--ext/js/pages/welcome-main.js7
7 files changed, 93 insertions, 67 deletions
diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js
index f8dd865f..9f72cc82 100644
--- a/ext/js/pages/action-popup-main.js
+++ b/ext/js/pages/action-popup-main.js
@@ -21,7 +21,7 @@ import {querySelectorNotNull} from '../dom/query-selector.js';
import {HotkeyHelpController} from '../input/hotkey-help-controller.js';
import {yomitan} from '../yomitan.js';
-export class DisplayController {
+class DisplayController {
constructor() {
/** @type {?import('settings').Options} */
this._optionsFull = null;
@@ -302,7 +302,8 @@ export class DisplayController {
}
}
-(async () => {
+/** Entry point. */
+async function main() {
await yomitan.prepare();
yomitan.api.logIndicatorClear();
@@ -311,4 +312,6 @@ export class DisplayController {
displayController.prepare();
yomitan.ready();
-})();
+}
+
+await main();
diff --git a/ext/js/pages/generic-page-main.js b/ext/js/pages/generic-page-main.js
index 176537ae..4bb4c7ac 100644
--- a/ext/js/pages/generic-page-main.js
+++ b/ext/js/pages/generic-page-main.js
@@ -19,7 +19,8 @@
import {DocumentFocusController} from '../dom/document-focus-controller.js';
import {ExtensionContentController} from './common/extension-content-controller.js';
-(() => {
+/** Entry point. */
+function main() {
const documentFocusController = new DocumentFocusController();
documentFocusController.prepare();
@@ -27,4 +28,6 @@ import {ExtensionContentController} from './common/extension-content-controller.
extensionContentController.prepare();
document.documentElement.dataset.loaded = 'true';
-})();
+}
+
+main();
diff --git a/ext/js/pages/info-main.js b/ext/js/pages/info-main.js
index 7445354f..593b7460 100644
--- a/ext/js/pages/info-main.js
+++ b/ext/js/pages/info-main.js
@@ -56,7 +56,63 @@ function getOperatingSystemDisplayName(os) {
}
}
-(async () => {
+/** */
+async function showAnkiConnectInfo() {
+ let ankiConnectVersion = null;
+ try {
+ ankiConnectVersion = await yomitan.api.getAnkiConnectVersion();
+ } catch (e) {
+ // NOP
+ }
+
+ /** @type {HTMLElement} */
+ const ankiVersionElement = querySelectorNotNull(document, '#anki-connect-version');
+ /** @type {HTMLElement} */
+ const ankiVersionContainerElement = querySelectorNotNull(document, '#anki-connect-version-container');
+ /** @type {HTMLElement} */
+ const ankiVersionUnknownElement = querySelectorNotNull(document, '#anki-connect-version-unknown-message');
+
+ ankiVersionElement.textContent = (ankiConnectVersion !== null ? `${ankiConnectVersion}` : 'Unknown');
+ ankiVersionContainerElement.dataset.hasError = `${ankiConnectVersion === null}`;
+ ankiVersionUnknownElement.hidden = (ankiConnectVersion !== null);
+}
+
+/** */
+async function showDictionaryInfo() {
+ let dictionaryInfos;
+ try {
+ dictionaryInfos = await yomitan.api.getDictionaryInfo();
+ } catch (e) {
+ return;
+ }
+
+ const fragment = document.createDocumentFragment();
+ let first = true;
+ for (const {title} of dictionaryInfos) {
+ if (first) {
+ first = false;
+ } else {
+ fragment.appendChild(document.createTextNode(', '));
+ }
+
+ const node = document.createElement('span');
+ node.className = 'installed-dictionary';
+ node.textContent = title;
+ fragment.appendChild(node);
+ }
+
+ /** @type {HTMLElement} */
+ const noneElement = querySelectorNotNull(document, '#installed-dictionaries-none');
+
+ noneElement.hidden = (dictionaryInfos.length !== 0);
+ /** @type {HTMLElement} */
+ const container = querySelectorNotNull(document, '#installed-dictionaries');
+ container.textContent = '';
+ container.appendChild(fragment);
+}
+
+/** Entry point. */
+async function main() {
try {
const documentFocusController = new DocumentFocusController();
documentFocusController.prepare();
@@ -92,58 +148,8 @@ function getOperatingSystemDisplayName(os) {
languageElement.textContent = `${language}`;
userAgentElement.textContent = userAgent;
- (async () => {
- let ankiConnectVersion = null;
- try {
- ankiConnectVersion = await yomitan.api.getAnkiConnectVersion();
- } catch (e) {
- // NOP
- }
-
- /** @type {HTMLElement} */
- const ankiVersionElement = querySelectorNotNull(document, '#anki-connect-version');
- /** @type {HTMLElement} */
- const ankiVersionContainerElement = querySelectorNotNull(document, '#anki-connect-version-container');
- /** @type {HTMLElement} */
- const ankiVersionUnknownElement = querySelectorNotNull(document, '#anki-connect-version-unknown-message');
-
- ankiVersionElement.textContent = (ankiConnectVersion !== null ? `${ankiConnectVersion}` : 'Unknown');
- ankiVersionContainerElement.dataset.hasError = `${ankiConnectVersion === null}`;
- ankiVersionUnknownElement.hidden = (ankiConnectVersion !== null);
- })();
-
- (async () => {
- let dictionaryInfos;
- try {
- dictionaryInfos = await yomitan.api.getDictionaryInfo();
- } catch (e) {
- return;
- }
-
- const fragment = document.createDocumentFragment();
- let first = true;
- for (const {title} of dictionaryInfos) {
- if (first) {
- first = false;
- } else {
- fragment.appendChild(document.createTextNode(', '));
- }
-
- const node = document.createElement('span');
- node.className = 'installed-dictionary';
- node.textContent = title;
- fragment.appendChild(node);
- }
-
- /** @type {HTMLElement} */
- const noneElement = querySelectorNotNull(document, '#installed-dictionaries-none');
-
- noneElement.hidden = (dictionaryInfos.length !== 0);
- /** @type {HTMLElement} */
- const container = querySelectorNotNull(document, '#installed-dictionaries');
- container.textContent = '';
- container.appendChild(fragment);
- })();
+ showAnkiConnectInfo();
+ showDictionaryInfo();
const settingsController = new SettingsController();
await settingsController.prepare();
@@ -157,4 +163,6 @@ function getOperatingSystemDisplayName(os) {
} catch (e) {
log.error(e);
}
-})();
+}
+
+await main();
diff --git a/ext/js/pages/permissions-main.js b/ext/js/pages/permissions-main.js
index 58dae310..e4ac3f3d 100644
--- a/ext/js/pages/permissions-main.js
+++ b/ext/js/pages/permissions-main.js
@@ -86,7 +86,8 @@ function setupPermissionsToggles() {
}
}
-(async () => {
+/** Entry point. */
+async function main() {
try {
const documentFocusController = new DocumentFocusController();
documentFocusController.prepare();
@@ -140,4 +141,6 @@ function setupPermissionsToggles() {
} catch (e) {
log.error(e);
}
-})();
+}
+
+await main();
diff --git a/ext/js/pages/settings/popup-preview-frame-main.js b/ext/js/pages/settings/popup-preview-frame-main.js
index bce485fe..7b42e11a 100644
--- a/ext/js/pages/settings/popup-preview-frame-main.js
+++ b/ext/js/pages/settings/popup-preview-frame-main.js
@@ -22,7 +22,8 @@ import {HotkeyHandler} from '../../input/hotkey-handler.js';
import {yomitan} from '../../yomitan.js';
import {PopupPreviewFrame} from './popup-preview-frame.js';
-(async () => {
+/** Entry point. */
+async function main() {
try {
await yomitan.prepare();
@@ -47,4 +48,6 @@ import {PopupPreviewFrame} from './popup-preview-frame.js';
} catch (e) {
log.error(e);
}
-})();
+}
+
+await main();
diff --git a/ext/js/pages/settings/settings-main.js b/ext/js/pages/settings/settings-main.js
index 3f0dac3f..3abe3bcf 100644
--- a/ext/js/pages/settings/settings-main.js
+++ b/ext/js/pages/settings/settings-main.js
@@ -58,7 +58,8 @@ async function setupGenericSettingsController(genericSettingController) {
await genericSettingController.refresh();
}
-(async () => {
+/** Entry point. */
+async function main() {
try {
const documentFocusController = new DocumentFocusController();
documentFocusController.prepare();
@@ -174,4 +175,6 @@ async function setupGenericSettingsController(genericSettingController) {
} catch (e) {
log.error(e);
}
-})();
+}
+
+await main();
diff --git a/ext/js/pages/welcome-main.js b/ext/js/pages/welcome-main.js
index d208e996..fbb60fe8 100644
--- a/ext/js/pages/welcome-main.js
+++ b/ext/js/pages/welcome-main.js
@@ -48,7 +48,8 @@ async function setupGenericSettingsController(genericSettingController) {
await genericSettingController.refresh();
}
-(async () => {
+/** Entry point. */
+async function main() {
try {
const documentFocusController = new DocumentFocusController();
documentFocusController.prepare();
@@ -104,4 +105,6 @@ async function setupGenericSettingsController(genericSettingController) {
} catch (e) {
log.error(e);
}
-})();
+}
+
+await main();