summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-02-26 11:05:41 -0800
committerAlex Yatskov <alex@foosoft.net>2017-02-26 11:05:41 -0800
commit32f95e59a9c5612d2b5658ea8a70b55ec17cca18 (patch)
treea75e426d9350f266402ff0e8a9d040a985a37629 /ext/bg
parentb7faaf0b51363b8366adae3ba7511d5232d6cd30 (diff)
parent8966dc1213d4af15c956dbd8976b80a1287c9fe0 (diff)
Merge branch 'dev' into firefox
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/guide.html11
-rw-r--r--ext/bg/js/ankiconnect.js11
-rw-r--r--ext/bg/js/database.js78
-rw-r--r--ext/bg/js/options-form.js89
-rw-r--r--ext/bg/js/options.js50
-rw-r--r--ext/bg/js/templates.js98
-rw-r--r--ext/bg/js/yomichan.js76
-rw-r--r--ext/bg/legal.html4
-rw-r--r--ext/bg/options.html27
9 files changed, 179 insertions, 265 deletions
diff --git a/ext/bg/guide.html b/ext/bg/guide.html
index 23704934..4b0835b8 100644
--- a/ext/bg/guide.html
+++ b/ext/bg/guide.html
@@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8">
<title>Welcome to Yomichan!</title>
- <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css">
+ <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.7-dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css">
</head>
<body>
<div class="container">
@@ -23,11 +23,10 @@
</p>
<ol>
- <li>Left-click on the <img src="../img/icon16.png" alt> icon to enable or disable Yomichan for the current browser instance.</li>
- <li>Right-click on the <img src="../img/icon16.png" alt> icon and select <em>Options</em> to open the Yomichan options page.</li>
- <li>Import any dictionaries (bundled or custom) you wish to use for Kanji and term searches; none are imported by default.</li>
+ <li>Click on the <img src="../img/icon16.png" alt> icon in the browser toolbar to open the Yomichan options page.</li>
+ <li>Import the dictionaries (bundled or custom) you wish to use for term and Kanji searches.</li>
<li>Hold down <kbd>Shift</kbd> (or the middle mouse button) as you hover over text to see term definitions.</li>
- <li>Resize the definitions window by dragging the bottom-left corner inwards or outwards to make it smaller or larger.</li>
+ <li>Click on the <img src="../fg/img/play_audio.png" alt> icon to hear the term pronounced by a native speaker (if audio is available).</li>
<li>Click on Kanji in the definition window to view additional information about that character.</li>
</ol>
</div>
diff --git a/ext/bg/js/ankiconnect.js b/ext/bg/js/ankiconnect.js
index d17f3268..3a6e3690 100644
--- a/ext/bg/js/ankiconnect.js
+++ b/ext/bg/js/ankiconnect.js
@@ -17,9 +17,10 @@
*/
class AnkiConnect {
- constructor() {
+ constructor(server) {
+ this.server = server;
this.asyncPools = {};
- this.localVersion = 1;
+ this.localVersion = 2;
this.remoteVersion = null;
}
@@ -50,8 +51,8 @@ class AnkiConnect {
return this.ankiInvoke('version', {}, null).then(version => {
this.remoteVersion = version;
- if (this.remoteVersion !== this.localVersion) {
- return Promise.reject('extension and plugin version mismatch');
+ if (this.remoteVersion < this.localVersion) {
+ 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}));
});
}
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index cae96306..3b2bcfcb 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -45,7 +45,7 @@ class Database {
terms: '++id,dictionary,expression,reading',
kanji: '++,dictionary,character',
tagMeta: '++,dictionary',
- dictionaries: '++,title,version',
+ dictionaries: '++,title,version'
});
return this.db.open();
@@ -155,82 +155,6 @@ class Database {
return this.db.dictionaries.toArray();
}
- deleteDictionary(title, callback) {
- if (this.db === null) {
- return Promise.reject('database not initialized');
- }
-
- return this.db.dictionaries.where('title').equals(title).first(info => {
- if (!info) {
- return;
- }
-
- let termCounter = Promise.resolve(0);
- if (info.hasTerms) {
- termCounter = this.db.terms.where('dictionary').equals(title).count();
- }
-
- let kanjiCounter = Promise.resolve(0);
- if (info.hasKanji) {
- kanjiCounter = this.db.kanji.where('dictionary').equals(title).count();
- }
-
- return Promise.all([termCounter, kanjiCounter]).then(([termCount, kanjiCount]) => {
- const rowLimit = 500;
- const totalCount = termCount + kanjiCount;
- let deletedCount = 0;
-
- let termDeleter = Promise.resolve();
- if (info.hasTerms) {
- const termDeleterFunc = () => {
- return this.db.terms.where('dictionary').equals(title).limit(rowLimit).delete().then(count => {
- if (count === 0) {
- return Promise.resolve();
- }
-
- deletedCount += count;
- if (callback) {
- callback(totalCount, deletedCount);
- }
-
- return termDeleterFunc();
- });
- };
-
- termDeleter = termDeleterFunc();
- }
-
- let kanjiDeleter = Promise.resolve();
- if (info.hasKanji) {
- const kanjiDeleterFunc = () => {
- return this.db.kanji.where('dictionary').equals(title).limit(rowLimit).delete().then(count => {
- if (count === 0) {
- return Promise.resolve();
- }
-
- deletedCount += count;
- if (callback) {
- callback(totalCount, deletedCount);
- }
-
- return kanjiDeleterFunc();
- });
- };
-
- kanjiDeleter = kanjiDeleterFunc();
- }
-
- return Promise.all([termDeleter, kanjiDeleter]);
- });
- }).then(() => {
- return this.db.tagMeta.where('dictionary').equals(title).delete();
- }).then(() => {
- return this.db.dictionaries.where('title').equals(title).delete();
- }).then(() => {
- delete this.cacheTagMeta[title];
- });
- }
-
importDictionary(indexUrl, callback) {
if (this.db === null) {
return Promise.reject('database not initialized');
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index 92596773..ae0491a2 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -28,7 +28,7 @@ function getFormData() {
return optionsLoad().then(optionsOld => {
const optionsNew = $.extend(true, {}, optionsOld);
- optionsNew.general.autoStart = $('#activate-on-startup').prop('checked');
+ optionsNew.general.enable = $('#enable-search').prop('checked');
optionsNew.general.audioPlayback = $('#audio-playback-buttons').prop('checked');
optionsNew.general.groupResults = $('#group-terms-results').prop('checked');
optionsNew.general.softKatakana = $('#soft-katakana-search').prop('checked');
@@ -37,6 +37,7 @@ function getFormData() {
optionsNew.scanning.requireShift = $('#hold-shift-to-scan').prop('checked');
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
+ optionsNew.scanning.imposter = $('#search-form-text-fields').prop('checked');
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10);
@@ -44,6 +45,7 @@ function getFormData() {
optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/);
optionsNew.anki.htmlCards = $('#generate-html-cards').prop('checked');
optionsNew.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10);
+ optionsNew.anki.server = $('#interface-server').val();
if (optionsOld.anki.enable) {
optionsNew.anki.terms.deck = $('#anki-terms-deck').val();
optionsNew.anki.terms.model = $('#anki-terms-model').val();
@@ -85,7 +87,7 @@ $(document).ready(() => {
Handlebars.partials = Handlebars.templates;
optionsLoad().then(options => {
- $('#activate-on-startup').prop('checked', options.general.autoStart);
+ $('#enable-search').prop('checked', options.general.enable);
$('#audio-playback-buttons').prop('checked', options.general.audioPlayback);
$('#group-terms-results').prop('checked', options.general.groupResults);
$('#soft-katakana-search').prop('checked', options.general.softKatakana);
@@ -94,6 +96,7 @@ $(document).ready(() => {
$('#hold-shift-to-scan').prop('checked', options.scanning.requireShift);
$('#select-matched-text').prop('checked', options.scanning.selectText);
+ $('#search-form-text-fields').prop('checked', options.scanning.imposter);
$('#scan-delay').val(options.scanning.delay);
$('#scan-length').val(options.scanning.length);
@@ -106,6 +109,7 @@ $(document).ready(() => {
$('#card-tags').val(options.anki.tags.join(' '));
$('#generate-html-cards').prop('checked', options.anki.htmlCards);
$('#sentence-detection-extent').val(options.anki.sentenceExt);
+ $('#interface-server').val(options.anki.server);
$('input, select').not('.anki-model').change(onOptionsChanged);
$('.anki-model').change(onAnkiModelChanged);
@@ -164,11 +168,10 @@ function populateDictionaries(options) {
++dictCount;
});
+ updateVisibility(options);
+
$('.dict-enabled, .dict-priority').change(onOptionsChanged);
- $('.dict-delete').click(onDictionaryDelete);
- }).catch(error => {
- showDictionaryError(error);
- }).then(() => {
+ }).catch(showDictionaryError).then(() => {
showDictionarySpinner(false);
if (dictCount === 0) {
dictWarning.show();
@@ -185,36 +188,17 @@ function onDictionaryPurge(e) {
const dictControls = $('#dict-importer, #dict-groups').hide();
const dictProgress = $('#dict-purge-progress').show();
- return database().purge().catch(error => {
- showDictionaryError(error);
- }).then(() => {
+ return database().purge().catch(showDictionaryError).then(() => {
showDictionarySpinner(false);
dictControls.show();
dictProgress.hide();
- return optionsLoad().then(options => populateDictionaries(options));
- });
-}
-
-function onDictionaryDelete() {
- showDictionaryError(null);
- showDictionarySpinner(true);
-
- const dictGroup = $(this).closest('.dict-group');
- const dictProgress = dictGroup.find('.dict-delete-progress').show();
- const dictControls = dictGroup.find('.dict-group-controls').hide();
- const setProgress = percent => {
- dictProgress.find('.progress-bar').css('width', `${percent}%`);
- };
-
- setProgress(0.0);
-
- database().deleteDictionary(dictGroup.data('title'), (total, current) => setProgress(current / total * 100.0)).catch(error => {
- showDictionaryError(error);
- }).then(() => {
- showDictionarySpinner(false);
- dictProgress.hide();
- dictControls.show();
- return optionsLoad().then(options => populateDictionaries(options));
+ return optionsLoad();
+ }).then(options => {
+ options.dictionaries = {};
+ return optionsSave(options).then(() => {
+ populateDictionaries(options);
+ yomichan().setOptions(options);
+ });
});
}
@@ -225,9 +209,7 @@ function onDictionaryImport() {
const dictUrl = $('#dict-url');
const dictImporter = $('#dict-importer').hide();
const dictProgress = $('#dict-import-progress').show();
- const setProgress = percent => {
- dictProgress.find('.progress-bar').css('width', `${percent}%`);
- };
+ const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
setProgress(0.0);
@@ -235,11 +217,7 @@ function onDictionaryImport() {
database().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => {
options.dictionaries[summary.title] = {enabled: true, priority: 0};
return optionsSave(options).then(() => yomichan().setOptions(options));
- }).then(() => {
- return populateDictionaries(options);
- }).catch(error => {
- showDictionaryError(error);
- }).then(() => {
+ }).then(() => populateDictionaries(options)).catch(showDictionaryError).then(() => {
showDictionarySpinner(false);
dictProgress.hide();
dictImporter.show();
@@ -324,13 +302,7 @@ function populateAnkiDeckAndModel(options) {
populateAnkiFields($('#anki-terms-model').val(options.anki.terms.model), options),
populateAnkiFields($('#anki-kanji-model').val(options.anki.kanji.model), options)
]);
- }).then(() => {
- ankiFormat.show();
- }).catch(error => {
- showAnkiError(error);
- }).then(() => {
- showAnkiSpinner(false);
- });
+ }).then(() => ankiFormat.show()).catch(showAnkiError).then(() => showAnkiSpinner(false));
}
function populateAnkiFields(element, options) {
@@ -345,7 +317,7 @@ function populateAnkiFields(element, options) {
const markers = {
'terms': ['audio', 'dictionary', 'expression', 'furigana', 'glossary', 'reading', 'sentence', 'tags', 'url'],
- 'kanji': ['character', 'dictionary', 'glossary', 'kunyomi', 'onyomi', 'url']
+ 'kanji': ['character', 'dictionary', 'glossary', 'kunyomi', 'onyomi', 'sentence', 'tags', 'url']
}[tabId] || {};
return anki().getModelFieldNames(modelName).then(names => {
@@ -380,11 +352,7 @@ function onAnkiModelChanged(e) {
optionsNew.anki[tabId].fields = {};
populateAnkiFields(element, optionsNew).then(() => {
optionsSave(optionsNew).then(() => yomichan().setOptions(optionsNew));
- }).catch(error => {
- showAnkiError(error);
- }).then(() => {
- showAnkiSpinner(false);
- });
+ }).catch(showAnkiError).then(() => showAnkiSpinner(false));
});
}
@@ -397,15 +365,16 @@ function onOptionsChanged(e) {
return optionsSave(optionsNew).then(() => {
yomichan().setOptions(optionsNew);
updateVisibility(optionsNew);
- if (optionsNew.anki.enable !== optionsOld.anki.enable) {
+
+ const ankiUpdated =
+ optionsNew.anki.enable !== optionsOld.anki.enable ||
+ optionsNew.anki.server !== optionsOld.anki.server;
+
+ if (ankiUpdated) {
showAnkiError(null);
showAnkiSpinner(true);
return populateAnkiDeckAndModel(optionsNew);
}
});
- }).catch(error => {
- showAnkiError(error);
- }).then(() => {
- showAnkiSpinner(false);
- });
+ }).catch(showAnkiError).then(() => showAnkiSpinner(false));
}
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 25e0945c..7a47c702 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -20,7 +20,7 @@
function optionsSetDefaults(options) {
const defaults = {
general: {
- autoStart: true,
+ enable: true,
audioPlayback: true,
groupResults: true,
softKatakana: true,
@@ -31,6 +31,7 @@ function optionsSetDefaults(options) {
scanning: {
requireShift: true,
selectText: true,
+ imposter: true,
delay: 15,
length: 10
},
@@ -39,6 +40,7 @@ function optionsSetDefaults(options) {
anki: {
enable: false,
+ server: 'http://127.0.0.1:8765',
tags: ['yomichan'],
htmlCards: true,
sentenceExt: 200,
@@ -48,8 +50,8 @@ function optionsSetDefaults(options) {
};
const combine = (target, source) => {
- for (let key in source) {
- if (!(key in target)) {
+ for (const key in source) {
+ if (!target.hasOwnProperty(key)) {
target[key] = source[key];
}
}
@@ -67,14 +69,11 @@ function optionsSetDefaults(options) {
function optionsVersion(options) {
- const copy = (targetDict, targetKey, sourceDict, sourceKey) => {
- targetDict[targetKey] = sourceDict.hasOwnProperty(sourceKey) ? sourceDict[sourceKey] : targetDict[targetKey];
- };
-
- options.version = options.version || 0;
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, 'audioPlayback', options, 'enableAudioPlayback');
@@ -98,23 +97,7 @@ function optionsVersion(options) {
copy(options.anki.kanji, 'model', options, 'ankiKanjiModel');
copy(options.anki.kanji, 'fields', options, 'ankiKanjiFields');
- const fixupFields = fields => {
- const fixups = {
- '{expression-furigana}': '{furigana}',
- '{glossary-list}': '{glossary}'
- };
-
- for (let name in fields) {
- for (let fixup in fixups) {
- fields[name] = fields[name].replace(fixup, fixups[fixup]);
- }
- }
- };
-
- fixupFields(options.anki.terms.fields);
- fixupFields(options.anki.kanji.fields);
-
- for (let title in options.dictionaries) {
+ for (const title in options.dictionaries) {
const dictionary = options.dictionaries[title];
dictionary.enabled = dictionary.enableTerms || dictionary.enableKanji;
dictionary.priority = 0;
@@ -127,8 +110,8 @@ function optionsVersion(options) {
'{glossary-list}': '{glossary}'
};
- for (let name in fields) {
- for (let fixup in fixups) {
+ for (const name in fields) {
+ for (const fixup in fixups) {
fields[name] = fields[name].replace(fixup, fixups[fixup]);
}
}
@@ -139,10 +122,13 @@ function optionsVersion(options) {
}
];
- if (options.version < fixups.length) {
- fixups[options.version]();
- ++options.version;
- optionsVersion(options);
+ optionsSetDefaults(options);
+ if (!options.hasOwnProperty('version')) {
+ options.version = fixups.length;
+ }
+
+ while (options.version < fixups.length) {
+ fixups[options.version++]();
}
return options;
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index 01896aa6..5fb894c1 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -11,13 +11,9 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
+ " <small>rev."
+ alias4(((helper = (helper = helpers.revision || (depth0 != null ? depth0.revision : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"revision","hash":{},"data":data}) : helper)))
- + "</small></h4>\n\n <!-- <div class=\"row\"> -->\n <!-- <div class=\"col-xs-8\"> -->\n <!-- <h4><span class=\"text-muted glyphicon glyphicon-book\"></span> "
- + alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
- + " <small>v."
- + alias4(((helper = (helper = helpers.version || (depth0 != null ? depth0.version : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"version","hash":{},"data":data}) : helper)))
- + "</small></h4> -->\n <!-- </div> -->\n <!-- <div class=\"col-xs-4 text-right disabled\"> -->\n <!-- <button type=\"button\" class=\"dict-group-controls dict-delete btn btn-danger\">Delete</button> -->\n <!-- </div> -->\n <!-- </div> -->\n\n <div class=\"dict-delete-progress\">\n Dictionary data is being deleted, please be patient...\n <div class=\"progress\">\n <div class=\"progress-bar progress-bar-striped progress-bar-danger\" style=\"width: 0%\"></div>\n </div>\n </div>\n\n <div class=\"checkbox dict-group-controls\">\n <label><input type=\"checkbox\" class=\"dict-enabled\" "
+ + "</small></h4>\n\n <div class=\"checkbox\">\n <label><input type=\"checkbox\" class=\"dict-enabled\" "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.enabled : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "> Enable search</label>\n </div>\n <div class=\"form-group dict-group-controls options-advanced\">\n <label for=\"dict-"
+ + "> Enable search</label>\n </div>\n <div class=\"form-group options-advanced\">\n <label for=\"dict-"
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
+ "\">Result priority</label>\n <input type=\"number\" value=\""
+ alias4(((helper = (helper = helpers.priority || (depth0 != null ? depth0.priority : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"priority","hash":{},"data":data}) : helper)))
@@ -150,74 +146,104 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti
var stack1, alias1=depth0 != null ? depth0 : {};
return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(40, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.group : depth0),{"name":"if","hash":{},"fn":container.program(42, data, 0, blockParams, depths),"inverse":container.program(52, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "")
- + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(54, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
+ + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.modeKanji : depth0),{"name":"if","hash":{},"fn":container.program(42, data, 0, blockParams, depths),"inverse":container.program(51, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(64, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"40":function(container,depth0,helpers,partials,data) {
return "<div style=\"text-align: left;\">";
-},"42":function(container,depth0,helpers,partials,data,blockParams,depths) {
+},"42":function(container,depth0,helpers,partials,data) {
var stack1;
- return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(43, data, 0, blockParams, depths),"inverse":container.program(50, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
-},"43":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(43, data, 0),"inverse":container.program(49, data, 0),"data":data})) != null ? stack1 : "");
+},"43":function(container,depth0,helpers,partials,data) {
var stack1;
- return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(44, data, 0, blockParams, depths),"inverse":container.program(47, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
-},"44":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(44, data, 0),"inverse":container.program(47, data, 0),"data":data})) != null ? stack1 : "");
+},"44":function(container,depth0,helpers,partials,data) {
var stack1;
return "<ol>"
- + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(45, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1),{"name":"each","hash":{},"fn":container.program(45, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</ol>";
-},"45":function(container,depth0,helpers,partials,data,blockParams,depths) {
+},"45":function(container,depth0,helpers,partials,data) {
+ return "<li>"
+ + container.escapeExpression(container.lambda(depth0, depth0))
+ + "</li>";
+},"47":function(container,depth0,helpers,partials,data) {
+ var stack1;
+
+ return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
+},"49":function(container,depth0,helpers,partials,data) {
+ var stack1;
+
+ return container.escapeExpression(container.lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.glossary : stack1)) != null ? stack1["0"] : stack1), depth0));
+},"51":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ var stack1;
+
+ return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.group : depth0),{"name":"if","hash":{},"fn":container.program(52, data, 0, blockParams, depths),"inverse":container.program(62, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
+},"52":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ var stack1;
+
+ return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(53, data, 0, blockParams, depths),"inverse":container.program(60, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
+},"53":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ var stack1;
+
+ return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(54, data, 0, blockParams, depths),"inverse":container.program(57, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
+},"54":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ var stack1;
+
+ return "<ol>"
+ + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(55, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ + "</ol>";
+},"55":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1;
return "<li>"
+ ((stack1 = container.invokePartial(partials["glossary-single"],depth0,{"name":"glossary-single","hash":{"html":(depths[1] != null ? depths[1].html : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ "</li>";
-},"47":function(container,depth0,helpers,partials,data,blockParams,depths) {
+},"57":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1;
- return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(48, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
-},"48":function(container,depth0,helpers,partials,data,blockParams,depths) {
+ return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1),{"name":"each","hash":{},"fn":container.program(58, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
+},"58":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1;
return " * "
+ ((stack1 = container.invokePartial(partials["glossary-single"],depth0,{"name":"glossary-single","hash":{"html":(depths[1] != null ? depths[1].html : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
-},"50":function(container,depth0,helpers,partials,data) {
+},"60":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = container.invokePartial(partials["glossary-single"],((stack1 = ((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.definitions : stack1)) != null ? stack1["0"] : stack1),{"name":"glossary-single","hash":{"html":(depth0 != null ? depth0.html : depth0)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
-},"52":function(container,depth0,helpers,partials,data) {
+},"62":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = container.invokePartial(partials["glossary-single"],(depth0 != null ? depth0.definition : depth0),{"name":"glossary-single","hash":{"html":(depth0 != null ? depth0.html : depth0)},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
-},"54":function(container,depth0,helpers,partials,data) {
+},"64":function(container,depth0,helpers,partials,data) {
return "</div>";
-},"56":function(container,depth0,helpers,partials,data) {
+},"66":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.kunyomi : stack1),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
-},"58":function(container,depth0,helpers,partials,data) {
+},"68":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.onyomi : stack1),{"name":"each","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
-},"60":function(container,depth0,helpers,partials,data) {
+},"70":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.modeTermKana : depth0),{"name":"unless","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
-},"62":function(container,depth0,helpers,partials,data) {
+},"72":function(container,depth0,helpers,partials,data) {
var stack1;
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.sentence : stack1), depth0));
-},"64":function(container,depth0,helpers,partials,data) {
+},"74":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.tags : stack1),{"name":"each","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
-},"66":function(container,depth0,helpers,partials,data) {
+},"76":function(container,depth0,helpers,partials,data) {
var stack1;
- return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(67, data, 0),"inverse":container.program(69, data, 0),"data":data})) != null ? stack1 : "");
-},"67":function(container,depth0,helpers,partials,data) {
+ return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.html : depth0),{"name":"if","hash":{},"fn":container.program(77, data, 0),"inverse":container.program(79, data, 0),"data":data})) != null ? stack1 : "");
+},"77":function(container,depth0,helpers,partials,data) {
var stack1, alias1=container.lambda, alias2=container.escapeExpression;
return "<a href=\""
@@ -225,7 +251,7 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti
+ "\">"
+ alias2(alias1(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.url : stack1), depth0))
+ "</a>";
-},"69":function(container,depth0,helpers,partials,data) {
+},"79":function(container,depth0,helpers,partials,data) {
var stack1;
return container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.definition : depth0)) != null ? stack1.url : stack1), depth0));
@@ -245,12 +271,12 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti
fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(26, data, 0, blockParams, depths),"inverse":container.noop,"args":["expression"],"data":data}) || fn;
fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"args":["furigana"],"data":data}) || fn;
fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"args":["glossary"],"data":data}) || fn;
- fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(56, data, 0, blockParams, depths),"inverse":container.noop,"args":["kunyomi"],"data":data}) || fn;
- fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(58, data, 0, blockParams, depths),"inverse":container.noop,"args":["onyomi"],"data":data}) || fn;
- fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(60, data, 0, blockParams, depths),"inverse":container.noop,"args":["reading"],"data":data}) || fn;
- fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(62, data, 0, blockParams, depths),"inverse":container.noop,"args":["sentence"],"data":data}) || fn;
- fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(64, data, 0, blockParams, depths),"inverse":container.noop,"args":["tags"],"data":data}) || fn;
- fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(66, data, 0, blockParams, depths),"inverse":container.noop,"args":["url"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(66, data, 0, blockParams, depths),"inverse":container.noop,"args":["kunyomi"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(68, data, 0, blockParams, depths),"inverse":container.noop,"args":["onyomi"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(70, data, 0, blockParams, depths),"inverse":container.noop,"args":["reading"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(72, data, 0, blockParams, depths),"inverse":container.noop,"args":["sentence"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(74, data, 0, blockParams, depths),"inverse":container.noop,"args":["tags"],"data":data}) || fn;
+ fn = decorators.inline(fn,props,container,{"name":"inline","hash":{},"fn":container.program(76, data, 0, blockParams, depths),"inverse":container.noop,"args":["url"],"data":data}) || fn;
return fn;
}
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index d7bf0e80..b1bf710f 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -26,18 +26,12 @@ class Yomichan {
this.translator = new Translator();
this.anki = new AnkiNull();
this.options = null;
- this.setEnabled(false);
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
- chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this));
chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this));
+ chrome.browserAction.onClicked.addListener(e => chrome.runtime.openOptionsPage());
- this.translator.prepare().then(optionsLoad).then(options => {
- this.setOptions(options);
- if (this.options.general.autoStart) {
- this.setEnabled(true);
- }
- });
+ this.translator.prepare().then(optionsLoad).then(this.setOptions.bind(this));
}
onInstalled(details) {
@@ -57,21 +51,28 @@ class Yomichan {
return true;
}
- onBrowserAction() {
- this.setEnabled(!this.enabled);
- }
-
- setEnabled(enabled) {
- this.enabled = enabled;
- this.tabInvokeAll('setEnabled', this.enabled);
- chrome.browserAction.setBadgeText({text: enabled ? '' : 'off'});
- }
+ // setEnabled(enabled) {
+ // this.enabled = enabled;
+ // this.tabInvokeAll('setEnabled', this.enabled);
+ // chrome.browserAction.setBadgeText({text: enabled ? '' : 'off'});
+ // }
setOptions(options) {
this.options = options;
+ let usable = false;
+ for (const title in options.dictionaries) {
+ if (options.dictionaries[title].enabled) {
+ usable = true;
+ break;
+ }
+ }
+
+ chrome.browserAction.setBadgeBackgroundColor({color: '#f0ad4e'});
+ chrome.browserAction.setBadgeText({text: usable ? '' : '!'});
+
if (options.anki.enable) {
- this.anki = new AnkiConnect();
+ this.anki = new AnkiConnect(this.options.anki.server);
} else {
this.anki = new AnkiNull();
}
@@ -81,7 +82,7 @@ class Yomichan {
tabInvokeAll(action, params) {
chrome.tabs.query({}, tabs => {
- for (let tab of tabs) {
+ for (const tab of tabs) {
chrome.tabs.sendMessage(tab.id, {action, params}, () => null);
}
});
@@ -100,24 +101,27 @@ class Yomichan {
note.deckName = this.options.anki.terms.deck;
note.modelName = this.options.anki.terms.model;
- const audio = {
- kanji: definition.expression,
- kana: definition.reading,
- fields: []
- };
-
- for (let name in fields) {
- if (fields[name].includes('{audio}')) {
- audio.fields.push(name);
+ if (definition.audio) {
+ const audio = {
+ url: definition.audio.url,
+ filename: definition.audio.filename,
+ skipHash: '7e2c2f954ef6051373ba916f000168dc',
+ fields: []
+ };
+
+ for (const name in fields) {
+ if (fields[name].includes('{audio}')) {
+ audio.fields.push(name);
+ }
}
- }
- if (audio.fields.length > 0) {
- note.audio = audio;
+ if (audio.fields.length > 0) {
+ note.audio = audio;
+ }
}
}
- for (let name in fields) {
+ for (const name in fields) {
note.fields[name] = formatField(
fields[name],
definition,
@@ -129,10 +133,6 @@ class Yomichan {
return note;
}
- api_getEnabled({callback}) {
- callback({result: this.enabled});
- }
-
api_getOptions({callback}) {
promiseCallback(optionsLoad(), callback);
}
@@ -175,8 +175,8 @@ class Yomichan {
api_canAddDefinitions({definitions, modes, callback}) {
const notes = [];
- for (let definition of definitions) {
- for (let mode of modes) {
+ for (const definition of definitions) {
+ for (const mode of modes) {
notes.push(this.formatNote(definition, mode));
}
}
diff --git a/ext/bg/legal.html b/ext/bg/legal.html
index 16b32578..9be89f72 100644
--- a/ext/bg/legal.html
+++ b/ext/bg/legal.html
@@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8">
<title>Yomichan Legal</title>
- <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css">
+ <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.7-dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css">
</head>
<body>
<div class="container">
diff --git a/ext/bg/options.html b/ext/bg/options.html
index e5b0cbca..d6eeb121 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -3,11 +3,11 @@
<head>
<meta charset="UTF-8">
<title>Yomichan Options</title>
- <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css">
+ <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.7-dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css">
<style>
#anki-spinner, #anki-general, #anki-error,
- #dict-spinner, #dict-error, #dict-warning, #dict-purge-progress, #dict-import-progress, .dict-delete-progress,
+ #dict-spinner, #dict-error, #dict-warning, #dict-purge-progress, #dict-import-progress,
.options-advanced {
display: none;
}
@@ -26,7 +26,7 @@
<h3>General Options</h3>
<div class="checkbox">
- <label><input type="checkbox" id="activate-on-startup"> Activate on startup</label>
+ <label><input type="checkbox" id="enable-search"> Enable search</label>
</div>
<div class="checkbox">
@@ -62,6 +62,10 @@
<label><input type="checkbox" id="select-matched-text"> Select matched text</label>
</div>
+ <div class="checkbox">
+ <label><input type="checkbox" id="search-form-text-fields"> Search form text fields</label>
+ </div>
+
<div class="form-group options-advanced">
<label for="scan-delay">Scan delay</label>
<input type="number" min="1" id="scan-delay" class="form-control">
@@ -111,9 +115,9 @@
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
- <li><a href="#" data-url="edict">JMdict</a></li>
- <li><a href="#" data-url="enamdict">JMnedict</a></li>
- <li><a href="#" data-url="kanjidic">KANJIDIC2</a></li>
+ <li><a href="#" data-url="edict">JMdict <span class="text-muted">(terms)</span></a></li>
+ <li><a href="#" data-url="enamdict">JMnedict <span class="text-muted">(names)</span></a></li>
+ <li><a href="#" data-url="kanjidic">KANJIDIC2 <span class="text-muted">(characters)</span></a></li>
<li role="separator" class="divider"></li>
<li><a href="#" data-url="http://localhost:9876/index.json">Local dictionary</a></li>
</ul>
@@ -161,6 +165,11 @@
<input type="number" min="1" id="sentence-detection-extent" class="form-control">
</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">
<ul class="nav nav-tabs">
<li class="active"><a href="#terms" data-toggle="tab">Terms</a></li>
@@ -228,8 +237,8 @@
</div>
</div>
- <script src="../lib/jquery-2.2.2.min.js"></script>
- <script src="../lib/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
+ <script src="../lib/jquery-3.1.1.min.js"></script>
+ <script src="../lib/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="js/templates.js"></script>
<script src="js/gecko.js"></script>