aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-07-10 18:16:51 -0700
committerAlex Yatskov <alex@foosoft.net>2016-07-10 18:16:51 -0700
commit0eccd89f147f3ec94d38a4ddb8e20ce1016ae570 (patch)
treeba7a17cace47ceb402254fcb7702fa271087a5da /ext/bg/js
parent1476ed4b717597e6e35ac2e5987c7979711cff83 (diff)
Support additional replacement fields
Diffstat (limited to 'ext/bg/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;