aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/search.js3
-rw-r--r--ext/bg/js/settings-dictionaries.js42
-rw-r--r--ext/bg/js/settings-profiles.js8
-rw-r--r--ext/bg/js/settings.js3
4 files changed, 37 insertions, 19 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index aa56d1a6..56316217 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -223,6 +223,7 @@ class DisplaySearch extends Display {
} else {
this.container.textContent = '';
}
+ window.parent.postMessage('popupClose', '*');
} catch (e) {
this.onError(e);
}
@@ -255,7 +256,7 @@ class DisplaySearch extends Display {
} else if (IS_FIREFOX === false) {
curText = (await apiClipboardGet()).trim();
}
- if (curText && (curText !== this.clipboardPrevText)) {
+ if (curText && (curText !== this.clipboardPrevText) && jpIsJapaneseText(curText)) {
if (this.isWanakanaEnabled()) {
this.query.value = window.wanakana.toKana(curText);
} else {
diff --git a/ext/bg/js/settings-dictionaries.js b/ext/bg/js/settings-dictionaries.js
index 720b7d3d..ebd380ac 100644
--- a/ext/bg/js/settings-dictionaries.js
+++ b/ext/bg/js/settings-dictionaries.js
@@ -21,28 +21,40 @@ let dictionaryUI = null;
class SettingsDictionaryListUI {
- constructor(container, template, extraContainer, extraTemplate, optionsDictionaries) {
+ constructor(container, template, extraContainer, extraTemplate) {
this.container = container;
this.template = template;
this.extraContainer = extraContainer;
this.extraTemplate = extraTemplate;
- this.optionsDictionaries = optionsDictionaries;
-
+ this.optionsDictionaries = null;
+ this.dictionaries = null;
this.dictionaryEntries = [];
this.extra = null;
document.querySelector('#dict-delete-confirm').addEventListener('click', (e) => this.onDictionaryConfirmDelete(e), false);
}
+ setOptionsDictionaries(optionsDictionaries) {
+ this.optionsDictionaries = optionsDictionaries;
+ if (this.dictionaries !== null) {
+ this.setDictionaries(this.dictionaries);
+ }
+ }
+
setDictionaries(dictionaries) {
for (const dictionaryEntry of this.dictionaryEntries) {
dictionaryEntry.cleanup();
}
this.dictionaryEntries = [];
+ this.dictionaries = toIterable(dictionaries);
+
+ if (this.optionsDictionaries === null) {
+ return;
+ }
let changed = false;
- for (const dictionaryInfo of toIterable(dictionaries)) {
+ for (const dictionaryInfo of this.dictionaries) {
if (this.createEntry(dictionaryInfo)) {
changed = true;
}
@@ -52,7 +64,7 @@ class SettingsDictionaryListUI {
const titles = this.dictionaryEntries.map(e => e.dictionaryInfo.title);
const removeKeys = Object.keys(this.optionsDictionaries).filter(key => titles.indexOf(key) < 0);
- if (removeKeys.length >= 0) {
+ if (removeKeys.length > 0) {
for (const key of toIterable(removeKeys)) {
delete this.optionsDictionaries[key];
}
@@ -331,17 +343,13 @@ class SettingsDictionaryExtraUI {
async function dictSettingsInitialize() {
- const optionsContext = getOptionsContext();
- const options = await apiOptionsGet(optionsContext);
-
dictionaryUI = new SettingsDictionaryListUI(
document.querySelector('#dict-groups'),
document.querySelector('#dict-template'),
document.querySelector('#dict-groups-extra'),
- document.querySelector('#dict-extra-template'),
- options.dictionaries
+ document.querySelector('#dict-extra-template')
);
- dictionaryUI.save = () => apiOptionsSave();
+ dictionaryUI.save = () => settingsSaveOptions();
document.querySelector('#dict-purge-button').addEventListener('click', (e) => onDictionaryPurgeButtonClick(e), false);
document.querySelector('#dict-purge-confirm').addEventListener('click', (e) => onDictionaryPurge(e), false);
@@ -349,9 +357,17 @@ async function dictSettingsInitialize() {
document.querySelector('#dict-file').addEventListener('change', (e) => onDictionaryImport(e), false);
document.querySelector('#dict-main').addEventListener('change', (e) => onDictionaryMainChanged(e), false);
+ const optionsContext = getOptionsContext();
+ const options = await apiOptionsGet(optionsContext);
+ onDictionaryOptionsChanged(options);
onDatabaseUpdated(options);
}
+async function onDictionaryOptionsChanged(options) {
+ if (dictionaryUI === null) { return; }
+ dictionaryUI.setOptionsDictionaries(options.dictionaries);
+}
+
async function onDatabaseUpdated(options) {
try {
const dictionaries = await utilDatabaseGetDictionaryInfo();
@@ -397,7 +413,7 @@ async function updateMainDictionarySelect(options, dictionaries) {
if (options.general.mainDictionary !== value) {
options.general.mainDictionary = value;
- apiOptionsSave();
+ settingsSaveOptions();
}
}
@@ -406,7 +422,7 @@ async function onDictionaryMainChanged(e) {
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
options.general.mainDictionary = value;
- apiOptionsSave();
+ settingsSaveOptions();
}
diff --git a/ext/bg/js/settings-profiles.js b/ext/bg/js/settings-profiles.js
index ededc998..3ae9db14 100644
--- a/ext/bg/js/settings-profiles.js
+++ b/ext/bg/js/settings-profiles.js
@@ -95,7 +95,7 @@ async function profileFormWrite(optionsFull) {
$('#profile-add-condition-group')
);
profileConditionsContainer.save = () => {
- apiOptionsSave();
+ settingsSaveOptions();
conditionsClearCaches(profileConditionsDescriptor);
};
profileConditionsContainer.isolate = utilBackgroundIsolate;
@@ -166,7 +166,7 @@ async function onProfileOptionsChanged(e) {
const optionsFull = await apiOptionsGetFull();
await profileFormRead(optionsFull);
- await apiOptionsSave();
+ await settingsSaveOptions();
}
async function onTargetProfileChanged() {
@@ -188,7 +188,7 @@ async function onProfileAdd() {
optionsFull.profiles.push(profile);
currentProfileIndex = optionsFull.profiles.length - 1;
await profileOptionsUpdateTarget(optionsFull);
- await apiOptionsSave();
+ await settingsSaveOptions();
}
async function onProfileRemove(e) {
@@ -226,7 +226,7 @@ async function onProfileRemoveConfirm() {
}
await profileOptionsUpdateTarget(optionsFull);
- await apiOptionsSave();
+ await settingsSaveOptions();
}
function onProfileNameChanged() {
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index 129d5f10..4704d9b1 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -135,6 +135,7 @@ async function formWrite(options) {
$('#field-templates').val(options.anki.fieldTemplates);
onAnkiTemplatesValidateCompile();
+ await onDictionaryOptionsChanged(options);
try {
await ankiDeckAndModelPopulate(options);
@@ -318,7 +319,7 @@ async function audioSettingsInitialize() {
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
audioSourceUI = new AudioSourceUI.Container(options.audio.sources, $('.audio-source-list'), $('.audio-source-add'));
- audioSourceUI.save = () => apiOptionsSave();
+ audioSourceUI.save = () => settingsSaveOptions();
textToSpeechInitialize();
}