tweaks for ankiconnect
This commit is contained in:
parent
a13c32a784
commit
5076b80f96
@ -17,7 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class AnkiConnect {
|
class AnkiConnect {
|
||||||
constructor() {
|
constructor(server) {
|
||||||
|
this.server = server;
|
||||||
this.asyncPools = {};
|
this.asyncPools = {};
|
||||||
this.localVersion = 1;
|
this.localVersion = 1;
|
||||||
this.remoteVersion = null;
|
this.remoteVersion = null;
|
||||||
@ -50,8 +51,8 @@ class AnkiConnect {
|
|||||||
|
|
||||||
return this.ankiInvoke('version', {}, null).then(version => {
|
return this.ankiInvoke('version', {}, null).then(version => {
|
||||||
this.remoteVersion = version;
|
this.remoteVersion = version;
|
||||||
if (this.remoteVersion !== this.localVersion) {
|
if (this.remoteVersion < this.localVersion) {
|
||||||
return Promise.reject('extension and plugin version mismatch');
|
return Promise.reject('extension and plugin versions incompatible');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -75,7 +76,7 @@ class AnkiConnect {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
xhr.open('POST', 'http://127.0.0.1:8765');
|
xhr.open('POST', this.server);
|
||||||
xhr.send(JSON.stringify({action, params}));
|
xhr.send(JSON.stringify({action, params}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ function getFormData() {
|
|||||||
optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/);
|
optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/);
|
||||||
optionsNew.anki.htmlCards = $('#generate-html-cards').prop('checked');
|
optionsNew.anki.htmlCards = $('#generate-html-cards').prop('checked');
|
||||||
optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
|
optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
|
||||||
|
optionsNew.anki.server = $('#interface-server').val();
|
||||||
if (optionsOld.anki.enable) {
|
if (optionsOld.anki.enable) {
|
||||||
optionsNew.anki.terms.deck = $('#anki-terms-deck').val();
|
optionsNew.anki.terms.deck = $('#anki-terms-deck').val();
|
||||||
optionsNew.anki.terms.model = $('#anki-terms-model').val();
|
optionsNew.anki.terms.model = $('#anki-terms-model').val();
|
||||||
@ -106,6 +107,7 @@ $(document).ready(() => {
|
|||||||
$('#card-tags').val(options.anki.tags.join(' '));
|
$('#card-tags').val(options.anki.tags.join(' '));
|
||||||
$('#generate-html-cards').prop('checked', options.anki.htmlCards);
|
$('#generate-html-cards').prop('checked', options.anki.htmlCards);
|
||||||
$('#sentence-detection-extent').val(options.anki.sentenceExt);
|
$('#sentence-detection-extent').val(options.anki.sentenceExt);
|
||||||
|
$('#interface-server').val(options.anki.server);
|
||||||
$('input, select').not('.anki-model').change(onOptionsChanged);
|
$('input, select').not('.anki-model').change(onOptionsChanged);
|
||||||
$('.anki-model').change(onAnkiModelChanged);
|
$('.anki-model').change(onAnkiModelChanged);
|
||||||
|
|
||||||
@ -399,7 +401,7 @@ function onOptionsChanged(e) {
|
|||||||
return optionsSave(optionsNew).then(() => {
|
return optionsSave(optionsNew).then(() => {
|
||||||
yomichan().setOptions(optionsNew);
|
yomichan().setOptions(optionsNew);
|
||||||
updateVisibility(optionsNew);
|
updateVisibility(optionsNew);
|
||||||
if (optionsNew.anki.enable !== optionsOld.anki.enable) {
|
if (optionsNew.anki.enable !== optionsOld.anki.enable || optionsNew.anki.server !== optionsOld.anki.server) {
|
||||||
showAnkiError(null);
|
showAnkiError(null);
|
||||||
showAnkiSpinner(true);
|
showAnkiSpinner(true);
|
||||||
return populateAnkiDeckAndModel(optionsNew);
|
return populateAnkiDeckAndModel(optionsNew);
|
||||||
|
@ -39,6 +39,7 @@ function optionsSetDefaults(options) {
|
|||||||
|
|
||||||
anki: {
|
anki: {
|
||||||
enable: false,
|
enable: false,
|
||||||
|
server: 'http://127.0.0.1:8765',
|
||||||
tags: ['yomichan'],
|
tags: ['yomichan'],
|
||||||
htmlCards: true,
|
htmlCards: true,
|
||||||
sentenceExt: 200,
|
sentenceExt: 200,
|
||||||
@ -67,14 +68,14 @@ function optionsSetDefaults(options) {
|
|||||||
|
|
||||||
|
|
||||||
function optionsVersion(options) {
|
function optionsVersion(options) {
|
||||||
const copy = (targetDict, targetKey, sourceDict, sourceKey) => {
|
optionsSetDefaults(options);
|
||||||
targetDict[targetKey] = sourceDict.hasOwnProperty(sourceKey) ? sourceDict[sourceKey] : targetDict[targetKey];
|
|
||||||
};
|
|
||||||
|
|
||||||
options.version = options.version || 0;
|
options.version = options.version || 0;
|
||||||
|
|
||||||
const fixups = [
|
const fixups = [
|
||||||
() => {
|
() => {
|
||||||
optionsSetDefaults(options);
|
const copy = (targetDict, targetKey, sourceDict, sourceKey) => {
|
||||||
|
targetDict[targetKey] = sourceDict.hasOwnProperty(sourceKey) ? sourceDict[sourceKey] : targetDict[targetKey];
|
||||||
|
};
|
||||||
|
|
||||||
copy(options.general, 'autoStart', options, 'activateOnStartup');
|
copy(options.general, 'autoStart', options, 'activateOnStartup');
|
||||||
copy(options.general, 'audioPlayback', options, 'enableAudioPlayback');
|
copy(options.general, 'audioPlayback', options, 'enableAudioPlayback');
|
||||||
|
@ -71,7 +71,7 @@ class Yomichan {
|
|||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
if (options.anki.enable) {
|
if (options.anki.enable) {
|
||||||
this.anki = new AnkiConnect();
|
this.anki = new AnkiConnect(this.options.anki.server);
|
||||||
} else {
|
} else {
|
||||||
this.anki = new AnkiNull();
|
this.anki = new AnkiNull();
|
||||||
}
|
}
|
||||||
|
@ -161,6 +161,11 @@
|
|||||||
<input type="number" min="1" id="sentence-detection-extent" class="form-control">
|
<input type="number" min="1" id="sentence-detection-extent" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group options-advanced">
|
||||||
|
<label for="interface-server">Interface server</label>
|
||||||
|
<input type="text" id="interface-server" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="anki-format">
|
<div id="anki-format">
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li class="active"><a href="#terms" data-toggle="tab">Terms</a></li>
|
<li class="active"><a href="#terms" data-toggle="tab">Terms</a></li>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Yomichan",
|
"name": "Yomichan",
|
||||||
"version": "1.0.7",
|
"version": "1.0.8",
|
||||||
|
|
||||||
"description": "Japanese dictionary with Anki integration",
|
"description": "Japanese dictionary with Anki integration",
|
||||||
"icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"},
|
"icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"},
|
||||||
|
Loading…
Reference in New Issue
Block a user