Anki: term frequency colors in merged mode

This commit is contained in:
siikamiika 2017-10-19 19:27:28 +03:00
parent f54f909701
commit bc92327d86
2 changed files with 14 additions and 1 deletions

View File

@ -75,6 +75,18 @@ function handlebarsMultiLine(options) {
return options.fn(this).split('\n').join('<br>');
}
function handlebarsTermFrequencyColor(options) {
const termFrequency = options.fn(this);
if (termFrequency === 'popular') {
return '#0275d8';
} else if (termFrequency === 'rare') {
return '#999';
} else {
return 'inherit';
}
}
function handlebarsRegisterHelpers() {
if (Handlebars.partials !== Handlebars.templates) {
Handlebars.partials = Handlebars.templates;
@ -83,6 +95,7 @@ function handlebarsRegisterHelpers() {
Handlebars.registerHelper('furiganaPlain', handlebarsFuriganaPlain);
Handlebars.registerHelper('kanjiLinks', handlebarsKanjiLinks);
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
Handlebars.registerHelper('termFrequencyColor', handlebarsTermFrequencyColor);
}
}

View File

@ -79,7 +79,7 @@ function optionsFieldTemplates() {
{{#*inline "furigana"}}
{{~#if merge~}}
{{~#each definition.expressions~}}
{{~#furigana}}{{{.}}}{{/furigana~}}
<span style="color: {{#termFrequencyColor}}{{termFrequency}}{{/termFrequencyColor}}">{{~#furigana}}{{{.}}}{{/furigana~}}</span>
{{~#unless @last}}{{/unless~}}
{{~/each~}}
{{~else~}}