summaryrefslogtreecommitdiff
path: root/ext/js/pages/info-main.js
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/info-main.js
parent1d268edcc3efce723954bcaa7dd376f0352c1a32 (diff)
IIFE updates (#384)
* Remove most IIFEs * Move IIFEs into functions * Don't await background-main
Diffstat (limited to 'ext/js/pages/info-main.js')
-rw-r--r--ext/js/pages/info-main.js116
1 files changed, 62 insertions, 54 deletions
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();