summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/translator.js6
-rw-r--r--ext/bg/js/util.js2
-rw-r--r--ext/bg/js/yomichan.js24
-rw-r--r--ext/fg/js/driver.js11
-rw-r--r--ext/fg/js/frame.js31
-rw-r--r--ext/fg/js/popup.js4
-rw-r--r--ext/fg/js/util.js4
7 files changed, 78 insertions, 4 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index bdd606b7..8710f568 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -82,6 +82,12 @@ class Translator {
});
}
+ findTermGrouped(text, dictionaries, enableSoftKatakanaSearch) {
+ return this.findTerm(text, dictionaries, enableSoftKatakanaSearch).then(({length, definitions}) => {
+ return {length, definitions: groupTermDefs(definitions)};
+ });
+ }
+
findKanji(text, dictionaries) {
const processed = {}, promises = [];
for (const c of text) {
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 3fa01a10..19d08a7c 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -116,7 +116,7 @@ function groupTermDefs(definitions) {
const tagCounts = {};
for (const tag of groupDefs.map(def => def.tags)) {
- const count = tagsGlobal[tag.name] || 0;
+ const count = tagCounts[tag.name] || 0;
tagCounts[tag.name] = count + 1;
}
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 69397a61..f96e4437 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -188,7 +188,29 @@ class Yomichan {
}
promiseCallback(
- this.translator.findTerm(text, dictionaries, this.options.enableSoftKatakanaSearch),
+ this.translator.findTerm(
+ text,
+ dictionaries,
+ this.options.enableSoftKatakanaSearch
+ ),
+ callback
+ );
+ }
+
+ api_findTermGrouped({text, callback}) {
+ const dictionaries = [];
+ for (const title in this.options.dictionaries) {
+ if (this.options.dictionaries[title].enableTerms) {
+ dictionaries.push(title);
+ }
+ }
+
+ promiseCallback(
+ this.translator.findTermGrouped(
+ text,
+ dictionaries,
+ this.options.enableSoftKatakanaSearch
+ ),
callback
);
}
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js
index c0e328d5..12003d55 100644
--- a/ext/fg/js/driver.js
+++ b/ext/fg/js/driver.js
@@ -146,7 +146,14 @@ class Driver {
searchTerms(textSource) {
textSource.setEndOffset(this.options.scanLength);
- return findTerm(textSource.text()).then(({definitions, length}) => {
+ let findFunc = findTerm;
+ let showFunc = this.popup.showTermDefs.bind(this.popup);
+ if (this.options.groupTermResults) {
+ findFunc = findTermGrouped;
+ showFunc = this.popup.showTermGroupedDefs.bind(this.popup);
+ }
+
+ return findFunc(textSource.text()).then(({definitions, length}) => {
if (definitions.length === 0) {
return false;
} else {
@@ -159,7 +166,7 @@ class Driver {
});
this.popup.showNextTo(textSource.getRect());
- this.popup.showTermDefs(definitions, this.options);
+ showFunc(definitions, this.options);
this.lastTextSource = textSource;
if (this.options.selectMatchedText) {
textSource.select();
diff --git a/ext/fg/js/frame.js b/ext/fg/js/frame.js
index 95762d5e..fc32a718 100644
--- a/ext/fg/js/frame.js
+++ b/ext/fg/js/frame.js
@@ -61,6 +61,37 @@ class Frame {
});
}
+ api_showTermGroupedDefs({definitions, options}) {
+ const sequence = ++this.sequence;
+ const context = {
+ definitions,
+ addable: options.ankiMethod !== 'disabled',
+ playback: options.enableAudioPlayback
+ };
+
+ this.definitions = definitions;
+ this.showSpinner(false);
+ window.scrollTo(0, 0);
+
+ renderText(context, 'term-list.html').then(content => {
+ $('.content').html(content);
+ $('.action-add-note').click(this.onAddNote.bind(this));
+
+ $('.kanji-link').click(e => {
+ e.preventDefault();
+ findKanji($(e.target).text()).then(kdefs => this.api_showKanjiDefs({options, definitions: kdefs}));
+ });
+
+ $('.action-play-audio').click(e => {
+ e.preventDefault();
+ const index = $(e.currentTarget).data('index');
+ this.playAudio(this.definitions[index]);
+ });
+
+ this.updateAddNoteButtons(['term_kanji', 'term_kana'], sequence);
+ });
+ }
+
api_showKanjiDefs({definitions, options}) {
const sequence = ++this.sequence;
const context = {
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 21f4a9d7..d2c78081 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -74,6 +74,10 @@ class Popup {
this.invokeApi('showTermDefs', {definitions, options});
}
+ showTermGroupedDefs(definitions, options) {
+ this.invokeApi('showTermGroupedDefs', {definitions, options});
+ }
+
showKanjiDefs(definitions, options) {
this.invokeApi('showKanjiDefs', {definitions, options});
}
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index aae044c5..cedfb887 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -41,6 +41,10 @@ function findTerm(text) {
return invokeBgApi('findTerm', {text});
}
+function findTermGrouped(text) {
+ return invokeBgApi('findTermGrouped', {text});
+}
+
function findKanji(text) {
return invokeBgApi('findKanji', {text});
}