aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/anki.js6
-rw-r--r--ext/bg/js/backend.js8
-rw-r--r--ext/bg/js/context-main.js2
-rw-r--r--ext/bg/js/info-main.js123
-rw-r--r--ext/bg/js/settings/backup-controller.js36
5 files changed, 163 insertions, 12 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js
index 8395518f..8693bc9a 100644
--- a/ext/bg/js/anki.js
+++ b/ext/bg/js/anki.js
@@ -49,6 +49,12 @@ class AnkiConnect {
}
}
+ async getVersion() {
+ if (!this._enabled) { return null; }
+ await this._checkVersion();
+ return await this._invoke('version', {});
+ }
+
async addNote(note) {
if (!this._enabled) { return null; }
await this._checkVersion();
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 012036dc..b2ea3cd6 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -90,6 +90,7 @@ class Backend {
['kanjiFind', {async: true, contentScript: true, handler: this._onApiKanjiFind.bind(this)}],
['termsFind', {async: true, contentScript: true, handler: this._onApiTermsFind.bind(this)}],
['textParse', {async: true, contentScript: true, handler: this._onApiTextParse.bind(this)}],
+ ['getAnkiConnectVersion', {async: true, contentScript: true, handler: this._onApGetAnkiConnectVersion.bind(this)}],
['isAnkiConnected', {async: true, contentScript: true, handler: this._onApiIsAnkiConnected.bind(this)}],
['addAnkiNote', {async: true, contentScript: true, handler: this._onApiAddAnkiNote.bind(this)}],
['getAnkiNoteInfo', {async: true, contentScript: true, handler: this._onApiGetAnkiNoteInfo.bind(this)}],
@@ -428,6 +429,10 @@ class Backend {
return results;
}
+ async _onApGetAnkiConnectVersion() {
+ return await this._anki.getVersion();
+ }
+
async _onApiIsAnkiConnected() {
return await this._anki.isConnected();
}
@@ -786,7 +791,8 @@ class Backend {
}
_onCommandHelp() {
- chrome.tabs.create({url: 'https://foosoft.net/projects/yomichan/'});
+ const url = chrome.runtime.getURL('/bg/info.html');
+ chrome.tabs.create({url});
}
_onCommandOptions(params) {
diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js
index b6736fd8..96b54a99 100644
--- a/ext/bg/js/context-main.js
+++ b/ext/bg/js/context-main.js
@@ -30,7 +30,7 @@ class DisplayController {
this._showExtensionInfo(manifest);
this._setupEnvironment();
this._setupButtonEvents('.action-open-search', 'search', chrome.runtime.getURL('/bg/search.html'));
- this._setupButtonEvents('.action-open-help', 'help', 'https://foosoft.net/projects/yomichan/');
+ this._setupButtonEvents('.action-open-help', 'help', chrome.runtime.getURL('/bg/info.html'));
const optionsFull = await api.optionsGetFull();
this._optionsFull = optionsFull;
diff --git a/ext/bg/js/info-main.js b/ext/bg/js/info-main.js
new file mode 100644
index 00000000..04455a4f
--- /dev/null
+++ b/ext/bg/js/info-main.js
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2020 Yomichan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+/* global
+ * BackupController
+ * SettingsController
+ * api
+ */
+
+function getBrowserDisplayName(browser) {
+ switch (browser) {
+ case 'chrome': return 'Chrome';
+ case 'firefox': return 'Firefox';
+ case 'firefox-mobile': return 'Firefox for Android';
+ case 'edge': return 'Edge';
+ case 'edge-legacy': return 'Edge Legacy';
+ default: return `${browser}`;
+ }
+}
+
+function getOperatingSystemDisplayName(os) {
+ switch (os) {
+ case 'mac': return 'Mac OS';
+ case 'win': return 'Windows';
+ case 'android': return 'Android';
+ case 'cros': return 'Chrome OS';
+ case 'linux': return 'Linux';
+ case 'openbsd': return 'Open BSD';
+ case 'unknown': return 'Unknown';
+ default: return `${os}`;
+ }
+}
+
+(async () => {
+ try {
+ document.querySelector('#content-scroll-focus').focus();
+
+ const manifest = chrome.runtime.getManifest();
+
+ api.forwardLogsToBackend();
+ await yomichan.prepare();
+
+ const {userAgent} = navigator;
+ const {version} = manifest;
+ const {browser, platform: {os}} = await api.getEnvironmentInfo();
+
+ const thisVersionLink = document.querySelector('#release-notes-this-version-link');
+ thisVersionLink.href = thisVersionLink.dataset.hrefFormat.replace(/\{version\}/g, version);
+
+ document.querySelector('#version').textContent = `${version}`;
+ document.querySelector('#browser').textContent = getBrowserDisplayName(browser);
+ document.querySelector('#platform').textContent = getOperatingSystemDisplayName(os);
+ document.querySelector('#user-agent').textContent = userAgent;
+
+ (async () => {
+ let ankiConnectVersion = null;
+ try {
+ ankiConnectVersion = await api.getAnkiConnectVersion();
+ } catch (e) {
+ // NOP
+ }
+
+ document.querySelector('#anki-connect-version').textContent = (ankiConnectVersion !== null ? `${ankiConnectVersion}` : 'Unknown');
+ document.querySelector('#anki-connect-version-container').hasError = `${ankiConnectVersion === null}`;
+ document.querySelector('#anki-connect-version-unknown-message').hidden = (ankiConnectVersion !== null);
+ })();
+
+ (async () => {
+ let dictionaryInfos;
+ try {
+ dictionaryInfos = await 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);
+ }
+
+ document.querySelector('#installed-dictionaries-none').hidden = (dictionaryInfos.length !== 0);
+ const container = document.querySelector('#installed-dictionaries');
+ container.textContent = '';
+ container.appendChild(fragment);
+ })();
+
+ const settingsController = new SettingsController();
+ settingsController.prepare();
+
+ const backupController = new BackupController(settingsController, null);
+ await backupController.prepare();
+
+ await promiseTimeout(100);
+
+ document.documentElement.dataset.loaded = 'true';
+ } catch (e) {
+ yomichan.logError(e);
+ }
+})();
diff --git a/ext/bg/js/settings/backup-controller.js b/ext/bg/js/settings/backup-controller.js
index b37dd91d..50a145ff 100644
--- a/ext/bg/js/settings/backup-controller.js
+++ b/ext/bg/js/settings/backup-controller.js
@@ -31,25 +31,41 @@ class BackupController {
this._settingsResetModal = null;
this._settingsImportErrorModal = null;
this._settingsImportWarningModal = null;
- this._optionsUtil = new OptionsUtil();
+ this._optionsUtil = null;
+ try {
+ this._optionsUtil = new OptionsUtil();
+ } catch (e) {
+ // NOP
+ }
}
async prepare() {
- await this._optionsUtil.prepare();
+ if (this._optionsUtil !== null) {
+ await this._optionsUtil.prepare();
+ }
- this._settingsResetModal = this._modalController.getModal('settings-reset');
- this._settingsImportErrorModal = this._modalController.getModal('settings-import-error');
- this._settingsImportWarningModal = this._modalController.getModal('settings-import-warning');
+ if (this._modalController !== null) {
+ this._settingsResetModal = this._modalController.getModal('settings-reset');
+ this._settingsImportErrorModal = this._modalController.getModal('settings-import-error');
+ this._settingsImportWarningModal = this._modalController.getModal('settings-import-warning');
+ }
- document.querySelector('#settings-export-button').addEventListener('click', this._onSettingsExportClick.bind(this), false);
- document.querySelector('#settings-import-button').addEventListener('click', this._onSettingsImportClick.bind(this), false);
- document.querySelector('#settings-import-file').addEventListener('change', this._onSettingsImportFileChange.bind(this), false);
- document.querySelector('#settings-reset-button').addEventListener('click', this._onSettingsResetClick.bind(this), false);
- document.querySelector('#settings-reset-confirm-button').addEventListener('click', this._onSettingsResetConfirmClick.bind(this), false);
+ this._addNodeEventListener('#settings-export-button', 'click', this._onSettingsExportClick.bind(this), false);
+ this._addNodeEventListener('#settings-import-button', 'click', this._onSettingsImportClick.bind(this), false);
+ this._addNodeEventListener('#settings-import-file', 'change', this._onSettingsImportFileChange.bind(this), false);
+ this._addNodeEventListener('#settings-reset-button', 'click', this._onSettingsResetClick.bind(this), false);
+ this._addNodeEventListener('#settings-reset-confirm-button', 'click', this._onSettingsResetConfirmClick.bind(this), false);
}
// Private
+ _addNodeEventListener(selector, ...args) {
+ const node = document.querySelector(selector);
+ if (node === null) { return; }
+
+ node.addEventListener(...args);
+ }
+
_getSettingsExportDateString(date, dateSeparator, dateTimeSeparator, timeSeparator, resolution) {
const values = [
date.getUTCFullYear().toString(),