This commit is contained in:
Alex Yatskov 2016-10-11 19:45:36 -07:00
parent a949e66a6c
commit 82162a071a
3 changed files with 53 additions and 22 deletions

View File

@ -43,6 +43,18 @@ class AnkiConnect {
return this.ankiInvokeSafe('modelFieldNames', {modelName}, null); return this.ankiInvokeSafe('modelFieldNames', {modelName}, null);
} }
getStatus() {
return this.getVersion().then(version => {
if (version === null) {
return 'disconnected';
} else if (version === this.apiVersion) {
return 'ready';
} else {
return 'mismatch';
}
});
}
getVersion() { getVersion() {
return this.ankiInvoke('version', {}, null); return this.ankiInvoke('version', {}, null);
} }

View File

@ -39,8 +39,25 @@ function modelIdToFieldOptKey(id) {
function modelIdToMarkers(id) { function modelIdToMarkers(id) {
return { return {
'anki-term-model': ['audio', 'expression', 'glossary', 'glossary-list', 'reading', 'sentence', 'tags', 'url'], 'anki-term-model': [
'anki-kanji-model': ['character', 'glossary', 'glossary-list', 'kunyomi', 'onyomi', 'url'], 'audio',
'expression',
'expression-furigana',
'glossary',
'glossary-list',
'reading',
'sentence',
'tags',
'url'
],
'anki-kanji-model': [
'character',
'glossary',
'glossary-list',
'kunyomi',
'onyomi',
'url'
],
}[id]; }[id];
} }
@ -111,19 +128,21 @@ function populateAnkiDeckAndModel(opts) {
} }
function updateAnkiStatus() { function updateAnkiStatus() {
$('.error-dlg').hide(); // $('.error-dlg').hide();
yomichan().api_getVersion({callback: version => { // yomichan().api_getVersion({callback: version => {
if (version === null) { // if (version === null) {
$('.error-dlg-connection').show(); // $('.error-dlg-connection').show();
$('.options-anki-controls').hide(); // $('.options-anki-controls').hide();
} else if (version !== yomichan().getApiVersion()) { // } else if (version !== yomichan().getApiVersion()) {
$('.error-dlg-version').show(); // $('.error-dlg-version').show();
$('.options-anki-controls').hide(); // $('.options-anki-controls').hide();
} else { // } else {
$('.options-anki-controls').show(); // $('.options-anki-controls').show();
} // }
}}); // }});
$('.options-anki-controls').show();
} }
function populateAnkiFields(element, opts) { function populateAnkiFields(element, opts) {

View File

@ -103,10 +103,6 @@ class Yomichan {
this.tabInvokeAll('setOptions', this.options); this.tabInvokeAll('setOptions', this.options);
} }
getApiVersion() {
return 1;
}
tabInvokeAll(action, params) { tabInvokeAll(action, params) {
chrome.tabs.query({}, tabs => { chrome.tabs.query({}, tabs => {
for (const tab of tabs) { for (const tab of tabs) {
@ -124,6 +120,7 @@ class Yomichan {
'audio', 'audio',
'character', 'character',
'expression', 'expression',
'expression-furigana',
'glossary', 'glossary',
'glossary-list', 'glossary-list',
'kunyomi', 'kunyomi',
@ -145,6 +142,13 @@ class Yomichan {
value = definition.reading; value = definition.reading;
} }
break; break;
case 'expression-furigana':
if (mode === 'term_kana' && definition.reading) {
value = definition.reading;
} else {
value = `<ruby>${definition.expression}<rt>${definition.reading}</rt></ruby>`;
}
break;
case 'reading': case 'reading':
if (mode === 'term_kana') { if (mode === 'term_kana') {
value = null; value = null;
@ -274,10 +278,6 @@ class Yomichan {
api_getModelFieldNames({modelName, callback}) { api_getModelFieldNames({modelName, callback}) {
this.anki.getModelFieldNames(modelName).then(callback); this.anki.getModelFieldNames(modelName).then(callback);
} }
api_getVersion({callback}) {
this.anki.getVersion().then(callback);
}
} }
window.yomichan = new Yomichan(); window.yomichan = new Yomichan();