aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/database.js42
-rw-r--r--ext/bg/js/settings.js4
-rw-r--r--ext/bg/js/translator.js1
3 files changed, 41 insertions, 6 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index ea55416c..1760a70a 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -129,6 +129,21 @@ class Database {
return results;
}
+ async findKanjiFreq(kanji, titles) {
+ if (!this.db) {
+ throw 'database not initialized';
+ }
+
+ const results = [];
+ await this.db.kanjiFreq.where('character').equals(kanji).each(row => {
+ if (titles.includes(row.dictionary)) {
+ results.push({frequency: row.frequency, dictionary: row.dictionary});
+ }
+ });
+
+ return results;
+ }
+
async cacheTagMeta(titles) {
if (!this.db) {
throw 'database not initialized';
@@ -186,7 +201,7 @@ class Database {
});
}
- await this.db.terms.bulkAdd(utilIsolate(rows));
+ await this.db.terms.bulkAdd(rows);
};
const termFreqDataLoaded = async (title, entries, total, current) => {
@@ -203,7 +218,7 @@ class Database {
});
}
- await this.db.termFreq.bulkAdd(utilIsolate(rows));
+ await this.db.termFreq.bulkAdd(rows);
};
const kanjiDataLoaded = async (title, entries, total, current) => {
@@ -223,7 +238,24 @@ class Database {
});
}
- await this.db.kanji.bulkAdd(utilIsolate(rows));
+ await this.db.kanji.bulkAdd(rows);
+ };
+
+ const kanjiFreqDataLoaded = async (title, entries, total, current) => {
+ if (callback) {
+ callback(total, current);
+ }
+
+ const rows = [];
+ for (const [character, frequency] of entries) {
+ rows.push({
+ character,
+ frequency,
+ dictionary: title
+ });
+ }
+
+ await this.db.kanjiFreq.bulkAdd(rows);
};
const tagDataLoaded = async (title, entries, total, current) => {
@@ -244,7 +276,7 @@ class Database {
rows.push(row);
}
- await this.db.tagMeta.bulkAdd(utilIsolate(rows));
+ await this.db.tagMeta.bulkAdd(rows);
};
return await Database.importDictionaryZip(
@@ -253,7 +285,7 @@ class Database {
termDataLoaded,
termFreqDataLoaded,
kanjiDataLoaded,
- null,
+ kanjiFreqDataLoaded,
tagDataLoaded
);
}
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index 55b469d0..b5ac8c8b 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -82,7 +82,9 @@ function formUpdateVisibility(options) {
const debug = $('#debug');
if (options.general.debugInfo) {
- const text = JSON.stringify(options, null, 4);
+ const temp = utilIsolate(options);
+ temp.anki.fieldTemplates = '...';
+ const text = JSON.stringify(temp, null, 4);
debug.html(handlebarsEscape(text));
debug.show();
} else {
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 3b9a1128..1e79b6fc 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -127,6 +127,7 @@ class Translator {
const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));
tags.push(dictTagBuildSource(definition.dictionary));
definition.tags = dictTagsSort(tags);
+ definition.frequencies = await this.database.findKanjiFreq(definition.character, titles);
}
return definitions;