From 92fbc14e0bea1ca04dd78f0ac788c528918cb133 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 5 Nov 2016 18:10:49 -0700 Subject: WIP --- ext/bg/options.html | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ext/bg/options.html') diff --git a/ext/bg/options.html b/ext/bg/options.html index 42029727..458174bb 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -62,6 +62,13 @@ +
+

Dictionaries

+ +
+
+
+
-- cgit v1.2.3 From c24e179b10d31c445ab6393fe1a39b570887a3aa Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 5 Nov 2016 18:24:45 -0700 Subject: WIP --- ext/bg/js/dictionary.js | 12 ++++++++++-- ext/bg/js/options-form.js | 11 +++++++++++ ext/bg/options.html | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'ext/bg/options.html') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 37a799a6..aa5f0b47 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -20,7 +20,7 @@ class Dictionary { constructor() { this.db = null; - this.dbVer = 5; + this.dbVer = 4; this.entities = null; } @@ -131,6 +131,14 @@ class Dictionary { }); } + getDictionaries() { + if (this.db === null) { + return Promise.reject('database not initialized'); + } + + return this.db.dictionaries.toArray(); + } + importTermDict(indexUrl, callback) { if (this.db === null) { return Promise.reject('database not initialized'); @@ -204,6 +212,6 @@ class Dictionary { }); }; - return importJsonDb(indexUrl, null, entriesLoaded); + return importJsonDb(indexUrl, indexLoaded, entriesLoaded); } } diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index eb562142..589d92b1 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -154,6 +154,16 @@ function populateAnkiDeckAndModel(opts) { }); } +function populateDictionaries() { + const dictionaries = $('.dictionaries'); + yomichan().translator.dictionary.getDictionaries().then(rows => { + for (const row of rows) { + const dictionary = $('

').text(row.dictionary); + dictionaries.append(dictionary); + } + }); +} + function populateAnkiFields(element, opts) { const table = element.closest('.tab-pane').find('.anki-fields'); table.find('tbody').remove(); @@ -274,6 +284,7 @@ $(document).ready(() => { $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); + populateDictionaries(); populateAnkiDeckAndModel(opts); updateVisibility(opts); }); diff --git a/ext/bg/options.html b/ext/bg/options.html index 458174bb..77d7edf1 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -65,7 +65,7 @@

Dictionaries

-
+
-- cgit v1.2.3 From 5172155c7813965ca8f896940fa30e613f08ebac Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 12:06:56 -0800 Subject: WIP --- ext/bg/options.html | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'ext/bg/options.html') diff --git a/ext/bg/options.html b/ext/bg/options.html index 77d7edf1..1136eefc 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -66,6 +66,49 @@

Dictionaries

+
+
+
+

Dictionary v.1

+
+
+ +
+
+ +
+ +
+
+ +
+
+
+ +
+ Error: + Something went wrong! +
+ +
+
+
+ +
+ + +
+ +
-- cgit v1.2.3 From fd6622400f64b2d568d38bde72f9fd75f8d06beb Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 17:10:31 -0800 Subject: Templates --- ext/bg/js/dictionary.js | 10 +++++----- ext/bg/js/options-form.js | 36 +++++++++++++++++------------------- ext/bg/js/templates.js | 18 ++++++++++++++++++ ext/bg/js/util.js | 10 +++++++--- ext/bg/options.html | 14 ++++++++------ tmpl/dictionary.html | 21 +++++++++++++++++++++ 6 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 tmpl/dictionary.html (limited to 'ext/bg/options.html') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 5859350b..008bc483 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -131,7 +131,7 @@ class Dictionary { }); } - getNames() { + getInfo() { if (this.db === null) { return Promise.reject('database not initialized'); } @@ -144,8 +144,8 @@ class Dictionary { return Promise.reject('database not initialized'); } - const indexLoaded = (dictionary, version, entities) => { - return this.db.dictionaries.add({dictionary, version}).then(() => { + const indexLoaded = (dictionary, version, entities, hasTerms, hasKanji) => { + return this.db.dictionaries.add({dictionary, version, hasTerms, hasKanji}).then(() => { this.entities = entities || {}; const rows = []; @@ -161,7 +161,7 @@ class Dictionary { }); }; - const termsLoaded = (dictionary, version, entries, total, current) => { + const termsLoaded = (dictionary, entries, total, current) => { const rows = []; for (const [expression, reading, tags, ...glossary] of entries) { rows.push({ @@ -180,7 +180,7 @@ class Dictionary { }); }; - const kanjiLoaded = (dictionary, version, entries, total, current) => { + const kanjiLoaded = (dictionary, entries, total, current) => { const rows = []; for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) { rows.push({ diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 060ee269..ec603eed 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -155,25 +155,21 @@ function populateAnkiDeckAndModel(opts) { } function populateDictionaries() { - // const dictGroups = $('.dictionaries'); - // dictGroups.empty(); - - // yomichan().translator.dictionary.getNames().then(rows => { - // for (const row of rows) { - // const dictPanel = $('
', {class: 'dictionary panel panel-default'}); - // const dictRow = $('
', {class: 'panel-body row'}).appendTo(dictPanel); - - // const title = $('
', {class: 'col-xs-8'}); - // $('

').append().html(` ${row.dictionary} v.${row.version}`).appendTo(title); - // title.appendTo(dictRow); - - // const controls = $('
', {class: 'col-xs-4 text-right'}); - // $('\n
\n

\n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
\n"; +},"useData":true}); templates['footer.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { var helper; diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index eaa7dd01..e99cdeab 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -121,7 +121,13 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/')); return loadJson(indexUrl).then(index => { if (indexLoaded !== null) { - return indexLoaded(index.title, index.version).then(() => index); + return indexLoaded( + index.title, + index.version, + index.entities, + index.termBanks > 0, + index.kanjiBanks > 0 + ).then(() => index); } return index; @@ -134,7 +140,6 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { const bankUrl = `${indexDir}/term_bank_${i}.json`; loaders.push(() => loadJson(bankUrl).then(entries => termsLoaded( index.title, - index.version, entries, banksTotal, banksLoaded++ @@ -145,7 +150,6 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { const bankUrl = `${indexDir}/kanji_bank_${i}.json`; loaders.push(() => loadJson(bankUrl).then(entries => kanjiLoaded( index.title, - index.version, entries, banksTotal, banksLoaded++ diff --git a/ext/bg/options.html b/ext/bg/options.html index 1136eefc..acd786cf 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -124,18 +124,18 @@
- -

Yomichan features automatic flashcard creation for Anki, a free application designed to help you retain knowledge. While the AnkiConnect plugin offers the best experience, it is also possible to create flashcards through AnkiWeb, provided you already have an account.

+ +
@@ -217,6 +217,8 @@ + + diff --git a/tmpl/dictionary.html b/tmpl/dictionary.html new file mode 100644 index 00000000..21847722 --- /dev/null +++ b/tmpl/dictionary.html @@ -0,0 +1,21 @@ +
+
+
+

{{name}} v.{{version}}

+
+
+ +
+
+ + {{#if hasTerms}} +
+ +
+ {{/if}} + {{#if hasKanji}} +
+ +
+ {{/if}} +
-- cgit v1.2.3 From 73c7c225f11b9a1da550b9b866f106b188bd82ea Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 18:30:51 -0800 Subject: Save dictionary options --- ext/bg/js/options-form.js | 12 +++++++++++- ext/bg/options.html | 20 +------------------- 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'ext/bg/options.html') diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 3ea850b7..f9346d7d 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -91,6 +91,14 @@ function getFormValues() { optsNew.ankiKanjiModel = $('#anki-kanji-model').val(); optsNew.ankiKanjiFields = fieldsToDict($('#kanji .anki-field-value')); + $('.dictionary').each((index, element) => { + const dictionary = $(element); + const name = dictionary.data('name'); + const enableTerms = dictionary.find('.dict-enable-terms').prop('checked'); + const enableKanji = dictionary.find('.dict-enable-kanji').prop('checked'); + optsNew.dictionaries[name] = {enableTerms, enableKanji}; + }); + return { optsNew: sanitizeOptions(optsNew), optsOld: sanitizeOptions(optsOld) @@ -172,12 +180,14 @@ function populateDictionaries(opts) { container.append($(html)); }); + + container.find('.dictionary input').change(onOptionsChanged); }); } function populateAnkiFields(element, opts) { const tab = element.closest('.tab-pane'); - const container = tab.find('.anki-fields tbody'); + const container = tab.find('tbody'); container.empty(); const modelName = element.val(); diff --git a/ext/bg/options.html b/ext/bg/options.html index acd786cf..bc87d654 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -65,25 +65,7 @@

Dictionaries

-
-
-
-
-

Dictionary v.1

-
-
- -
-
- -
- -
-
- -
-
-
+
Error: -- cgit v1.2.3 From 7fa51d682f29fbf51ed1228ca8840ff60be48e5e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 18:58:00 -0800 Subject: More work on options --- ext/bg/js/options-form.js | 23 ++++++++++++++++++++--- ext/bg/js/templates.js | 2 +- ext/bg/options.html | 16 ++++++++-------- tmpl/dictionary.html | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-) (limited to 'ext/bg/options.html') diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index f9346d7d..9919031a 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -91,7 +91,7 @@ function getFormValues() { optsNew.ankiKanjiModel = $('#anki-kanji-model').val(); optsNew.ankiKanjiFields = fieldsToDict($('#kanji .anki-field-value')); - $('.dictionary').each((index, element) => { + $('.dict').each((index, element) => { const dictionary = $(element); const name = dictionary.data('name'); const enableTerms = dictionary.find('.dict-enable-terms').prop('checked'); @@ -163,7 +163,7 @@ function populateAnkiDeckAndModel(opts) { } function populateDictionaries(opts) { - const container = $('.dictionaries'); + const container = $('.dicts'); container.empty(); yomichan().translator.dictionary.getInfo().then(rows => { @@ -181,7 +181,7 @@ function populateDictionaries(opts) { container.append($(html)); }); - container.find('.dictionary input').change(onOptionsChanged); + container.find('.dict input').change(onOptionsChanged); }); } @@ -289,6 +289,23 @@ $(document).ready(() => { $('input, select').not('.anki-model').change(onOptionsChanged); $('.anki-model').change(onAnkiModelChanged); + $('#dict-import a').click(e => { + e.preventDefault(); + const control = $('#dict-import-url'); + const url = $(e.target).data('url'); + if (url.includes('/')) { + control.val(url); + } else { + control.val(chrome.extension.getURL(`bg/data/${url}`)); + } + control.trigger('change'); + }); + + $('#dict-import-url').on('change keyup paste', () => { + const disable = $('#dict-import-url').val().trim().length === 0; + $('#dict-import-start').prop('disabled', disable); + }); + populateDictionaries(opts); populateAnkiDeckAndModel(opts); updateVisibility(opts); diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index fe4d95ca..2caf6ba8 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -7,7 +7,7 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; - return "
\n
\n
\n

" + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) diff --git a/ext/bg/options.html b/ext/bg/options.html index bc87d654..800fe8e9 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -6,7 +6,7 @@