summaryrefslogtreecommitdiff
path: root/ext/bg/js/yomichan.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r--ext/bg/js/yomichan.js62
1 files changed, 39 insertions, 23 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 19c66186..cd4bd4c1 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -153,35 +153,51 @@ class Yomichan {
}
formatField(field, definition, mode) {
- const supported = ['character', 'expression', 'glossary', 'kunyomi', 'onyomi', 'reading'];
-
- for (let key in definition) {
- if (supported.indexOf(key) === -1) {
- continue;
+ const tags = [
+ 'character',
+ 'expression',
+ 'glossary',
+ 'glossary-list',
+ 'kunyomi',
+ 'onyomi',
+ 'reading',
+ 'tags',
+ ];
+
+ for (let tag of tags) {
+ let value = definition[tag] || null;
+ switch (tag) {
+ case 'expression':
+ if (mode === 'vocab_kana' && definition.reading) {
+ value = definition.reading;
+ }
+ break;
+ case 'reading':
+ if (mode === 'vocab_kana') {
+ value = null;
+ }
+ break;
+ case 'glossary-list':
+ if (definition.glossary) {
+ value = '<ol>';
+ for (let gloss of definition.glossary) {
+ value += `<li>${gloss}</li>`;
+ }
+ value += '</ol>';
+ }
+ break;
+ case 'tags':
+ if (definition.tags) {
+ value = definition.tags.map((t) => t.name);
+ }
+ break;
}
- let value = definition[key];
if (value !== null && typeof(value) !== 'string') {
value = value.join(', ');
}
- if (mode === 'vocab_kana') {
- if (key === 'expression') {
- value = definition.reading;
- } else if (key === 'reading') {
- value = null;
- }
- }
-
- if (mode !== 'kanji' && key === 'glossary') {
- value = '<ol>';
- for (let gloss of definition.glossary) {
- value += `<li>${gloss}</li>`;
- }
- value += '</ol>';
- }
-
- field = field.replace(`{${key}}`, value || '');
+ field = field.replace(`{${tag}}`, value || '');
}
return field;