From e6b592b4c06ee18017a03bb5148e2c4b64deb146 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 3 Apr 2017 09:15:06 -0700 Subject: [PATCH 1/8] fix problem creating notes with audio when audio is disabled --- ext/mixed/js/util.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index edd49873..c05fb679 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -103,6 +103,10 @@ function audioBuildFilename(definition) { } function audioInject(definition, fields, mode) { + if (mode === 'disabled') { + return Promise.resolve(true); + } + const filename = audioBuildFilename(definition); if (!filename) { return Promise.resolve(true); From bbe4afecf6a56f4bdaaafe083a3bf67191fd9cde Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 6 Apr 2017 21:07:55 -0700 Subject: [PATCH 2/8] wip --- ext/fg/js/util.js | 8 ++------ ext/mixed/js/display.js | 4 ++-- ext/mixed/js/util.js | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index a1bce660..59060221 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -205,14 +205,10 @@ function docClozeExtract(source, extent) { } const sentence = content.substring(startPos, endPos); - const clozePrefix = sentence.substring(0, position - startPos); - const clozeBody = source.text(); - const clozeSuffix = sentence.substring(position - startPos + clozeBody.length); + const padding = sentence.length - sentence.replace(/^\s+/, ''); return { sentence: sentence.trim(), - prefix: clozePrefix.trim(), - body: clozeBody.trim(), - suffix: clozeSuffix.trim() + offset: position - startPos - padding }; } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index f5ad4849..e77ca7da 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -74,7 +74,7 @@ class Display { if (context) { for (const definition of definitions) { - definition.cloze = context.cloze; + definition.cloze = clozeBuild(context.cloze); definition.url = context.url; } } @@ -108,7 +108,7 @@ class Display { if (context) { for (const definition of definitions) { - definition.cloze = context.cloze; + definition.cloze = clozeBuild(context.cloze); definition.url = context.url; } } diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index c05fb679..aeeb830e 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -17,6 +17,20 @@ */ +/* + * Cloze + */ + +function clozeBuild(sentence, offset, source) { + return { + sentence: sentence.trim(), + prefix: sentence.substring(0, offset).trim(), + body: source.trim(), + suffix: sentence.substring(offset + source.length).trim() + }; +} + + /* * Audio */ From c4b1a4a5b4811d7aaa70b3b83f740c9e3d2b86be Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 7 Apr 2017 21:17:13 -0700 Subject: [PATCH 3/8] wip --- ext/fg/js/driver.js | 8 ++++---- ext/fg/js/util.js | 8 ++++---- ext/mixed/js/display.js | 8 ++++---- ext/mixed/js/util.js | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 49147c8f..e94a4ac2 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -172,13 +172,13 @@ window.driver = new class { } else { textSource.setEndOffset(length); - const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt); + const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); const url = window.location.href; this.popup.showTermDefs( textSource.getRect(), definitions, this.options, - {cloze, url} + {sentence, url} ); this.lastTextSource = textSource; @@ -198,13 +198,13 @@ window.driver = new class { if (definitions.length === 0) { return false; } else { - const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt); + const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); const url = window.location.href; this.popup.showKanjiDefs( textSource.getRect(), definitions, this.options, - {cloze, url} + {sentence, url} ); this.lastTextSource = textSource; diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index 59060221..445efa5b 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -152,7 +152,7 @@ function docRangeFromPoint(point, imposter) { return null; } -function docClozeExtract(source, extent) { +function docSentenceExtract(source, extent) { const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'}; const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'}; const terminators = '…。..??!!'; @@ -204,11 +204,11 @@ function docClozeExtract(source, extent) { } } - const sentence = content.substring(startPos, endPos); - const padding = sentence.length - sentence.replace(/^\s+/, ''); + const text = content.substring(startPos, endPos); + const padding = text.length - text.replace(/^\s+/, ''); return { - sentence: sentence.trim(), + text: text.trim(), offset: position - startPos - padding }; } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index e77ca7da..973b7749 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -74,7 +74,7 @@ class Display { if (context) { for (const definition of definitions) { - definition.cloze = clozeBuild(context.cloze); + definition.cloze = clozeBuild(context.sentence, definition.source); definition.url = context.url; } } @@ -108,7 +108,7 @@ class Display { if (context) { for (const definition of definitions) { - definition.cloze = clozeBuild(context.cloze); + definition.cloze = clozeBuild(context.sentence, definition.source); definition.url = context.url; } } @@ -181,7 +181,7 @@ class Display { }; if (this.context) { - context.cloze = this.context.cloze; + context.sentence = this.context.sentence; context.url = this.context.url; } @@ -308,7 +308,7 @@ class Display { if (this.context && this.context.source) { const context = { url: this.context.source.url, - cloze: this.context.source.cloze, + sentence: this.context.source.sentence, index: this.context.source.index }; diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index aeeb830e..eae54f49 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -21,12 +21,12 @@ * Cloze */ -function clozeBuild(sentence, offset, source) { +function clozeBuild(sentence, source) { return { - sentence: sentence.trim(), - prefix: sentence.substring(0, offset).trim(), + sentence: sentence.text.trim(), + prefix: sentence.text.substring(0, sentence.offset).trim(), body: source.trim(), - suffix: sentence.substring(offset + source.length).trim() + suffix: sentence.text.substring(sentence.offset + source.length).trim() }; } From 1ba458ea821b9a39a2cf5eb388f81e4db4763207 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 8 Apr 2017 12:25:18 -0700 Subject: [PATCH 4/8] fixing cloze bug --- ext/bg/js/options.js | 3 --- ext/fg/js/util.js | 4 ++-- ext/mixed/js/display.js | 2 +- ext/mixed/js/util.js | 15 ++++++++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index ad8d83d8..51f242c2 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -368,9 +368,6 @@ function ankiFieldsPopulate(element, options) { ], 'kanji': [ 'character', - 'cloze-body', - 'cloze-prefix', - 'cloze-suffix', 'dictionary', 'glossary', 'kunyomi', diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index 445efa5b..e5705ffd 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -182,7 +182,7 @@ function docSentenceExtract(source, extent) { quoteStack = []; - let endPos = content.length - 1; + let endPos = content.length; for (let i = position; i <= endPos; ++i) { const c = content[i]; @@ -205,7 +205,7 @@ function docSentenceExtract(source, extent) { } const text = content.substring(startPos, endPos); - const padding = text.length - text.replace(/^\s+/, ''); + const padding = text.length - text.replace(/^\s+/, '').length; return { text: text.trim(), diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 973b7749..64d462ae 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -108,7 +108,7 @@ class Display { if (context) { for (const definition of definitions) { - definition.cloze = clozeBuild(context.sentence, definition.source); + definition.cloze = clozeBuild(context.sentence); definition.url = context.url; } } diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index eae54f49..62838674 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -22,12 +22,17 @@ */ function clozeBuild(sentence, source) { - return { - sentence: sentence.text.trim(), - prefix: sentence.text.substring(0, sentence.offset).trim(), - body: source.trim(), - suffix: sentence.text.substring(sentence.offset + source.length).trim() + const result = { + sentence: sentence.text.trim() }; + + if (source) { + result.prefix = sentence.text.substring(0, sentence.offset).trim(); + result.body = source.trim(); + result.suffix = sentence.text.substring(sentence.offset + source.length).trim(); + } + + return result; } From 04e7b47815db3421d43494fc2c56776b3f8d8347 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 8 Apr 2017 12:28:09 -0700 Subject: [PATCH 5/8] version bump --- ext/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/manifest.json b/ext/manifest.json index ba31a35d..68adb6c3 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Yomichan", - "version": "1.1.11", + "version": "1.1.12", "description": "Japanese dictionary with Anki integration", "icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"}, From 2a233bd62184de12d9f0ee6bf0c6985dafe497fd Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 8 Apr 2017 13:11:06 -0700 Subject: [PATCH 6/8] add hint about specifying anki model fields --- ext/bg/options.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ext/bg/options.html b/ext/bg/options.html index 939227b0..77ea0e3c 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -193,6 +193,13 @@ +

+ Specify the information you would like included in your flashcards in the field editor below. + Please be aware that Anki requires the first field in the model to be unique. It is highly recommended + that you set it to {expression} for term flashcards and {character} for + Kanji flashcards. +

+
-

+

Specify the information you would like included in your flashcards in the field editor below. Please be aware that Anki requires the first field in the model to be unique. It is highly recommended that you set it to {expression} for term flashcards and {character} for From d263a93d446096abfc33e47f591dbb71eb7fe928 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 8 Apr 2017 18:01:36 -0700 Subject: [PATCH 8/8] usage guide --- ext/bg/guide.html | 32 ++++++++++++++------------------ ext/bg/js/options.js | 2 ++ ext/bg/js/util.js | 6 +++++- ext/bg/js/yomichan.js | 10 ++-------- ext/bg/options.html | 4 ++++ 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/ext/bg/guide.html b/ext/bg/guide.html index 6c38e351..4b01ae7c 100644 --- a/ext/bg/guide.html +++ b/ext/bg/guide.html @@ -9,28 +9,24 @@

-

Thank you for downloading this extension! I hope that Yomichan will help you on your language learning journey.

+

+ Read the steps below to get up and running with Yomichan. For complete documentation, + visit the official homepage. +

-
-

Quick Guide

+
    +
  1. Click on the icon in the browser toolbar to open the Yomichan actions dialog.
  2. +
  3. Click on the monkey wrench icon in the middle to open the options page.
  4. +
  5. Import the dictionaries you wish to use for term and Kanji searches.
  6. +
  7. Hold down Shift key or the middle mouse button as you move your mouse over text to display definitions.
  8. +
  9. Click on the icon to hear the term pronounced by a native speaker.
  10. +
  11. Click on individual Kanji in the term definition results to view additional information about those characters.
  12. +
-

- Read the steps below to get up and running with Yomichan. For complete documentation, - visit the official homepage. -

- -
    -
  1. Click on the icon in the browser toolbar to open the Yomichan actions dialog.
  2. -
  3. Click on the monkey wrench icon in the middle to open the options page.
  4. -
  5. Import the dictionaries you wish to use for term and Kanji searches.
  6. -
  7. Hold down Shift key or the middle mouse button as you move your mouse over text to display definitions.
  8. -
  9. Click on the icon to hear the term pronounced by a native speaker.
  10. -
  11. Click on individual Kanji in the term definition results to view additional information about those characters.
  12. -
-
+

This startup notification can be turned off on the Yomichan options page.

diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 51f242c2..49544840 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -25,6 +25,7 @@ function formRead() { return optionsLoad().then(optionsOld => { const optionsNew = $.extend(true, {}, optionsOld); + optionsNew.general.showGuide = $('#show-usage-guide').prop('checked'); optionsNew.general.audioSource = $('#audio-playback-source').val(); optionsNew.general.audioVolume = $('#audio-playback-volume').val(); optionsNew.general.groupResults = $('#group-terms-results').prop('checked'); @@ -111,6 +112,7 @@ $(document).ready(() => { handlebarsRegister(); optionsLoad().then(options => { + $('#show-usage-guide').prop('checked', options.general.showGuide); $('#audio-playback-source').val(options.general.audioSource); $('#audio-playback-volume').val(options.general.audioVolume); $('#group-terms-results').prop('checked', options.general.groupResults); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 05c7ff27..64143ffe 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -89,7 +89,8 @@ function optionsSetDefaults(options) { showAdvanced: false, popupWidth: 400, popupHeight: 250, - popupOffset: 10 + popupOffset: 10, + showGuide: true }, scanning: { @@ -144,6 +145,9 @@ function optionsVersion(options) { } else { options.general.audioSource = 'disabled'; } + }, + () => { + options.general.showGuide = false; } ]; diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index feb74b6e..51e05c80 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -28,8 +28,8 @@ window.yomichan = new class { this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)).then(() => { chrome.commands.onCommand.addListener(this.onCommand.bind(this)); chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); - if (chrome.runtime.onInstalled) { - chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this)); + if (this.options.general.showGuide) { + chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')}); } }); } @@ -157,12 +157,6 @@ window.yomichan = new class { return Promise.resolve(handlebarsRender(template, data)); } - onInstalled(details) { - if (details.reason === 'install') { - chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')}); - } - } - onCommand(command) { const handlers = { search: () => { diff --git a/ext/bg/options.html b/ext/bg/options.html index 0e73178a..e6c5e8be 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -25,6 +25,10 @@

General Options

+
+ +
+