aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/database.js19
-rw-r--r--ext/bg/js/options.js15
-rw-r--r--ext/bg/js/settings/dictionaries.js21
-rw-r--r--ext/bg/js/util.js4
4 files changed, 48 insertions, 11 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 2d309f85..c6717560 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -332,9 +332,11 @@ class Database {
return result;
}
- async importDictionary(archive, progressCallback, exceptions) {
+ async importDictionary(archive, progressCallback, exceptions, details) {
this.validate();
+ const prefixWildcardsSupported = details.prefixWildcardsSupported;
+
const maxTransactionLength = 1000;
const bulkAdd = async (objectStoreName, items, total, current) => {
const db = this.db;
@@ -389,9 +391,7 @@ class Database {
rules,
score,
glossary,
- dictionary: summary.title,
- expressionReverse: stringReverse(expression),
- readingReverse: stringReverse(reading)
+ dictionary: summary.title
});
}
} else {
@@ -405,13 +405,18 @@ class Database {
glossary,
sequence,
termTags,
- dictionary: summary.title,
- expressionReverse: stringReverse(expression),
- readingReverse: stringReverse(reading)
+ dictionary: summary.title
});
}
}
+ if (prefixWildcardsSupported) {
+ for (const row of rows) {
+ row.expressionReverse = stringReverse(row.expression);
+ row.readingReverse = stringReverse(row.reading);
+ }
+ }
+
await bulkAdd('terms', rows, total, current);
};
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index e53a8a13..2d13f6d9 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -378,7 +378,15 @@ function profileOptionsUpdateVersion(options) {
* ]
*/
-const optionsVersionUpdates = [];
+const optionsVersionUpdates = [
+ (options) => {
+ options.global = {
+ database: {
+ prefixWildcardsSupported: false
+ }
+ };
+ }
+];
function optionsUpdateVersion(options, defaultProfileOptions) {
// Ensure profiles is an array
@@ -423,6 +431,11 @@ function optionsUpdateVersion(options, defaultProfileOptions) {
profile.options = profileOptionsUpdateVersion(profile.options);
}
+ // Version
+ if (typeof options.version !== 'number') {
+ options.version = 0;
+ }
+
// Generic updates
return optionsGenericApplyUpdates(options, optionsVersionUpdates);
}
diff --git a/ext/bg/js/settings/dictionaries.js b/ext/bg/js/settings/dictionaries.js
index 065a8abc..926b05b7 100644
--- a/ext/bg/js/settings/dictionaries.js
+++ b/ext/bg/js/settings/dictionaries.js
@@ -356,6 +356,7 @@ async function dictSettingsInitialize() {
document.querySelector('#dict-file-button').addEventListener('click', (e) => onDictionaryImportButtonClick(e), false);
document.querySelector('#dict-file').addEventListener('change', (e) => onDictionaryImport(e), false);
document.querySelector('#dict-main').addEventListener('change', (e) => onDictionaryMainChanged(e), false);
+ document.querySelector('#database-enable-prefix-wildcard-searches').addEventListener('change', (e) => onDatabaseEnablePrefixWildcardSearchesChanged(e), false);
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
@@ -366,6 +367,9 @@ async function dictSettingsInitialize() {
async function onDictionaryOptionsChanged(options) {
if (dictionaryUI === null) { return; }
dictionaryUI.setOptionsDictionaries(options.dictionaries);
+
+ const optionsFull = await apiOptionsGetFull();
+ document.querySelector('#database-enable-prefix-wildcard-searches').checked = optionsFull.global.database.prefixWildcardsSupported;
}
async function onDatabaseUpdated(options) {
@@ -575,6 +579,12 @@ async function onDictionaryImport(e) {
const exceptions = [];
const files = [...e.target.files];
+ const optionsFull = await apiOptionsGetFull();
+
+ const importDetails = {
+ prefixWildcardsSupported: optionsFull.global.database.prefixWildcardsSupported
+ };
+
for (let i = 0, ii = files.length; i < ii; ++i) {
setProgress(0.0);
if (ii > 1) {
@@ -582,7 +592,7 @@ async function onDictionaryImport(e) {
dictImportInfo.textContent = `(${i + 1} of ${ii})`;
}
- const summary = await utilDatabaseImport(files[i], updateProgress, exceptions);
+ const summary = await utilDatabaseImport(files[i], updateProgress, exceptions, importDetails);
for (const options of toIterable(await getOptionsArray())) {
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
dictionaryOptions.enabled = true;
@@ -616,3 +626,12 @@ async function onDictionaryImport(e) {
dictProgress.hide();
}
}
+
+
+async function onDatabaseEnablePrefixWildcardSearchesChanged(e) {
+ const optionsFull = await apiOptionsGetFull();
+ const v = !!e.target.checked;
+ if (optionsFull.global.database.prefixWildcardsSupported === v) { return; }
+ optionsFull.global.database.prefixWildcardsSupported = !!e.target.checked;
+ await settingsSaveOptions();
+}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 3dd5fd55..8175fdff 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -94,13 +94,13 @@ function utilDatabaseDeleteDictionary(dictionaryName, onProgress) {
return utilBackend().translator.database.deleteDictionary(dictionaryName, onProgress);
}
-async function utilDatabaseImport(data, progress, exceptions) {
+async function utilDatabaseImport(data, progress, exceptions, details) {
// Edge cannot read data on the background page due to the File object
// being created from a different window. Read on the same page instead.
if (EXTENSION_IS_BROWSER_EDGE) {
data = await utilReadFile(data);
}
- return utilBackend().translator.database.importDictionary(data, progress, exceptions);
+ return utilBackend().translator.database.importDictionary(data, progress, exceptions, details);
}
function utilReadFile(file) {