aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
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
parent1476ed4b717597e6e35ac2e5987c7979711cff83 (diff)
Support additional replacement fields
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/yomichan.js62
-rw-r--r--ext/bg/options.html4
2 files changed, 41 insertions, 25 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;
diff --git a/ext/bg/options.html b/ext/bg/options.html
index a0174c40..86739c58 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -116,7 +116,7 @@
</tbody>
</table>
- <p>Supported field tags: <code>{expression}</code>, <code>{reading}</code>, <code>{glossary}</code></p>
+ <p>Allowed tags: <code>{expression}</code>, <code>{reading}</code>, <code>{glossary}</code>, <code>{glossary-list}</code>, <code>{tags}</code></p>
</div>
<div id="kanji" class="tab-pane fade">
@@ -145,7 +145,7 @@
</tbody>
</table>
- <p>Supported field tags: <code>{character}</code>, <code>{onyomi}</code>, <code>{kunyomi}</code>, <code>{glossary}</code></p>
+ <p>Allowed tags: <code>{character}</code>, <code>{onyomi}</code>, <code>{kunyomi}</code>, <code>{glossary}</code>, <code>{glossary-list}</code></p>
</div>
</div>
</form>