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);
}
getStatus() {
return this.getVersion().then(version => {
if (version === null) {
return 'disconnected';
} else if (version === this.apiVersion) {
return 'ready';
} else {
return 'mismatch';
}
});
}
getVersion() {
return this.ankiInvoke('version', {}, null);
}

View File

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

View File

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