summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-04-08 18:04:37 -0700
committerAlex Yatskov <alex@foosoft.net>2017-04-08 18:04:37 -0700
commit1b49f91a9b252447ab791ccef7b26a0b8b6062dd (patch)
tree1cee3846da13d317be015a6ec4c244864e8b9247 /ext
parentbea50cca462be631dadbd2f5bde1bc0a12ad17bf (diff)
parentd263a93d446096abfc33e47f591dbb71eb7fe928 (diff)
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/guide.html32
-rw-r--r--ext/bg/js/options.js5
-rw-r--r--ext/bg/js/util.js6
-rw-r--r--ext/bg/js/yomichan.js10
-rw-r--r--ext/bg/options.html11
-rw-r--r--ext/fg/js/driver.js8
-rw-r--r--ext/fg/js/util.js16
-rw-r--r--ext/manifest.json2
-rw-r--r--ext/mixed/js/display.js8
-rw-r--r--ext/mixed/js/util.js23
10 files changed, 72 insertions, 49 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 @@
<body>
<div class="container">
<div class="page-header">
- <h1>Welcome to Yomichan!</h1>
+ <h1>Yomichan Usage Guide</h1>
</div>
- <p>Thank you for downloading this extension! I hope that Yomichan will help you on your language learning journey.</p>
+ <p>
+ Read the steps below to get up and running with Yomichan. For complete documentation,
+ visit the <a href="https://foosoft.net/projects/yomichan/" target="_blank">official homepage</a>.
+ </p>
- <div>
- <h2>Quick Guide</h2>
+ <ol>
+ <li>Click on the <img src="/mixed/img/icon16.png" alt> icon in the browser toolbar to open the Yomichan actions dialog.</li>
+ <li>Click on the <em>monkey wrench</em> icon in the middle to open the options page.</li>
+ <li>Import the dictionaries you wish to use for term and Kanji searches.</li>
+ <li>Hold down <kbd>Shift</kbd> key or the middle mouse button as you move your mouse over text to display definitions.</li>
+ <li>Click on the <img src="/mixed/img/play-audio.png" alt> icon to hear the term pronounced by a native speaker.</li>
+ <li>Click on individual Kanji in the term definition results to view additional information about those characters.</li>
+ </ol>
- <p>
- Read the steps below to get up and running with Yomichan. For complete documentation,
- visit the <a href="https://foosoft.net/projects/yomichan/" target="_blank">official homepage</a>.
- </p>
-
- <ol>
- <li>Click on the <img src="/mixed/img/icon16.png" alt> icon in the browser toolbar to open the Yomichan actions dialog.</li>
- <li>Click on the <em>monkey wrench</em> icon in the middle to open the options page.</li>
- <li>Import the dictionaries you wish to use for term and Kanji searches.</li>
- <li>Hold down <kbd>Shift</kbd> key or the middle mouse button as you move your mouse over text to display definitions.</li>
- <li>Click on the <img src="/mixed/img/play-audio.png" alt> icon to hear the term pronounced by a native speaker.</li>
- <li>Click on individual Kanji in the term definition results to view additional information about those characters.</li>
- </ol>
- </div>
+ <p>This startup notification can be turned off on the Yomichan options page.</p>
</div>
</body>
</html>
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index ad8d83d8..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);
@@ -368,9 +370,6 @@ function ankiFieldsPopulate(element, options) {
],
'kanji': [
'character',
- 'cloze-body',
- 'cloze-prefix',
- 'cloze-suffix',
'dictionary',
'glossary',
'kunyomi',
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 939227b0..e6c5e8be 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -26,6 +26,10 @@
<h3>General Options</h3>
<div class="checkbox">
+ <label><input type="checkbox" id="show-usage-guide"> Show usage guide on startup</label>
+ </div>
+
+ <div class="checkbox">
<label><input type="checkbox" id="group-terms-results"> Group term results</label>
</div>
@@ -193,6 +197,13 @@
<input type="text" id="interface-server" class="form-control">
</div>
+ <p class="help-block">
+ 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 <code>{expression}</code> for term flashcards and <code>{character}</code> for
+ Kanji flashcards.
+ </p>
+
<div id="anki-format">
<ul class="nav nav-tabs">
<li class="active"><a href="#terms" data-toggle="tab">Terms</a></li>
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 a1bce660..e5705ffd 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 = '…。..??!!';
@@ -182,7 +182,7 @@ function docClozeExtract(source, extent) {
quoteStack = [];
- let endPos = content.length - 1;
+ let endPos = content.length;
for (let i = position; i <= endPos; ++i) {
const c = content[i];
@@ -204,15 +204,11 @@ 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 text = content.substring(startPos, endPos);
+ const padding = text.length - text.replace(/^\s+/, '').length;
return {
- sentence: sentence.trim(),
- prefix: clozePrefix.trim(),
- body: clozeBody.trim(),
- suffix: clozeSuffix.trim()
+ text: text.trim(),
+ offset: position - startPos - padding
};
}
diff --git a/ext/manifest.json b/ext/manifest.json
index a19a0e52..17d063c4 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"},
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index f5ad4849..64d462ae 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.sentence, definition.source);
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.sentence);
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 edd49873..62838674 100644
--- a/ext/mixed/js/util.js
+++ b/ext/mixed/js/util.js
@@ -18,6 +18,25 @@
/*
+ * Cloze
+ */
+
+function clozeBuild(sentence, source) {
+ 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;
+}
+
+
+/*
* Audio
*/
@@ -103,6 +122,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);