Merge branch 'master' into dev

This commit is contained in:
Alex Yatskov 2017-01-11 20:44:53 -08:00
commit c574ef4bc0
7 changed files with 17 additions and 64 deletions

View File

@ -48,12 +48,8 @@ works, please see the [Yomichan Import](https://foosoft.net/projects/yomichan-im
## Anki Integration ## ## Anki Integration ##
Yomichan features automatic flashcard creation for [Anki](http://ankisrs.net/), a free application designed to help you Yomichan features automatic flashcard creation for [Anki](http://ankisrs.net/), a free application designed to help you
retain knowledge. While the [AnkiConnect](https://foosoft.net/projects/anki-connect/) plugin offers the best experience, retain knowledge. This functionality requires prior installation of the
it is also possible to create flashcards through [AnkiWeb](https://ankiweb.net/), provided you already have an account. [AnkiConnect](https://foosoft.net/projects/anki-connect/) plugin. The installation process can be done in three steps:
### Using AnkiConnect ###
Installing the AnkiConnect plugin for Anki is the preferred way of enabling automatic flashcard creation in Yomichan.
1. Open the *Install Add-on* dialog by selecting *Tools* > *Add-ons* > *Browse & Install* in Anki. 1. Open the *Install Add-on* dialog by selecting *Tools* > *Add-ons* > *Browse & Install* in Anki.
2. Input *2055492159* into the text box labeled *Code* and press the *OK* button to proceed. 2. Input *2055492159* into the text box labeled *Code* and press the *OK* button to proceed.
@ -61,19 +57,6 @@ Installing the AnkiConnect plugin for Anki is the preferred way of enabling auto
When using AnkiConnect, Anki must be kept running in the background for automatic flashcard creation to function. When using AnkiConnect, Anki must be kept running in the background for automatic flashcard creation to function.
### Using AnkiWeb ###
Yomichan is able to create flashcards directly on AnkiWeb, assuming you have [registered an
account](https://ankiweb.net/account/register). While this method can be convenient as it does not require Anki to be
running to running in the background, some features are not supported due to technical limitations:
* Preventing the creation of duplicate flashcards.
* Embedding audio in flashcards via the `{audio}` marker.
Your AnkiWeb login information must specified on the options page to make use of automatic flashcard creation. Note
that AnkiWeb will temporarily block your IP address if there are too many login attempts; if this happens, just try
again after waiting for about an hour.
### Flashcard Configuration ### ### Flashcard Configuration ###
Before flashcards can be automatically created through Yomichan, Anki must be configured as follows: Before flashcards can be automatically created through Yomichan, Anki must be configured as follows:
@ -117,6 +100,13 @@ Before flashcards can be automatically created through Yomichan, Anki must be co
## Frequently Asked Questions ## ## Frequently Asked Questions ##
* **What happened to AnkiWeb integration? Why was it removed?**
The author of Anki wants to maintain tight control of AnkiWeb by restricting automated web requests, while at the
same time not providing an API for adding or removing flash cards. As circumventing these restrictions led to
account restrictions placed on users of this extension, I was forced to remove this feature. Note that it is still
possible to automatically generate flashcards with the AnkiConnect plugin.
* **Is it possible to use Yomichan with files saved locally on my computer?** * **Is it possible to use Yomichan with files saved locally on my computer?**
It in order to be able use Yomichan with local files, you must first tick the *Allow access to file URLs* checkbox It in order to be able use Yomichan with local files, you must first tick the *Allow access to file URLs* checkbox

View File

@ -4,7 +4,6 @@
<script src="../lib/handlebars.min.js"></script> <script src="../lib/handlebars.min.js"></script>
<script src="../lib/dexie.min.js"></script> <script src="../lib/dexie.min.js"></script>
<script src="../lib/wanakana.min.js"></script> <script src="../lib/wanakana.min.js"></script>
<script src="js/ankiweb.js"></script>
<script src="js/ankiconnect.js"></script> <script src="js/ankiconnect.js"></script>
<script src="js/ankinull.js"></script> <script src="js/ankinull.js"></script>
<script src="js/templates.js"></script> <script src="js/templates.js"></script>

View File

@ -40,8 +40,6 @@ function getFormValues() {
optsNew.scanLength = parseInt($('#scan-length').val(), 10); optsNew.scanLength = parseInt($('#scan-length').val(), 10);
optsNew.ankiMethod = $('#anki-method').val(); optsNew.ankiMethod = $('#anki-method').val();
optsNew.ankiUsername = $('#anki-username').val();
optsNew.ankiPassword = $('#anki-password').val();
optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/); optsNew.ankiCardTags = $('#anki-card-tags').val().split(/[,; ]+/);
optsNew.sentenceExtent = parseInt($('#sentence-extent').val(), 10); optsNew.sentenceExtent = parseInt($('#sentence-extent').val(), 10);
optsNew.ankiTermDeck = $('#anki-term-deck').val(); optsNew.ankiTermDeck = $('#anki-term-deck').val();
@ -68,13 +66,8 @@ function getFormValues() {
function updateVisibility(opts) { function updateVisibility(opts) {
switch (opts.ankiMethod) { switch (opts.ankiMethod) {
case 'ankiweb':
$('#anki-general').show();
$('.anki-login').show();
break;
case 'ankiconnect': case 'ankiconnect':
$('#anki-general').show(); $('#anki-general').show();
$('.anki-login').hide();
break; break;
default: default:
$('#anki-general').hide(); $('#anki-general').hide();
@ -104,8 +97,6 @@ $(document).ready(() => {
$('#scan-length').val(opts.scanLength); $('#scan-length').val(opts.scanLength);
$('#anki-method').val(opts.ankiMethod); $('#anki-method').val(opts.ankiMethod);
$('#anki-username').val(opts.ankiUsername);
$('#anki-password').val(opts.ankiPassword);
$('#anki-card-tags').val(opts.ankiCardTags.join(' ')); $('#anki-card-tags').val(opts.ankiCardTags.join(' '));
$('#sentence-extent').val(opts.sentenceExtent); $('#sentence-extent').val(opts.sentenceExtent);
@ -433,16 +424,7 @@ function onOptionsChanged(e) {
return saveOptions(optsNew).then(() => { return saveOptions(optsNew).then(() => {
yomichan().setOptions(optsNew); yomichan().setOptions(optsNew);
updateVisibility(optsNew); updateVisibility(optsNew);
if (optsNew.ankiMethod !== optsOld.ankiMethod) {
const loginChanged =
optsNew.ankiUsername !== optsOld.ankiUsername ||
optsNew.ankiPassword !== optsOld.ankiPassword;
if (loginChanged && optsNew.ankiMethod === 'ankiweb') {
showAnkiError(null);
showAnkiSpinner(true);
return anki().logout().then(() => populateAnkiDeckAndModel(optsNew));
} else if (optsNew.ankiMethod !== optsOld.ankiMethod) {
showAnkiError(null); showAnkiError(null);
showAnkiSpinner(true); showAnkiSpinner(true);
return populateAnkiDeckAndModel(optsNew); return populateAnkiDeckAndModel(optsNew);

View File

@ -45,8 +45,6 @@ function sanitizeOptions(options) {
dictionaries: {}, dictionaries: {},
ankiMethod: 'disabled', ankiMethod: 'disabled',
ankiUsername: '',
ankiPassword: '',
ankiCardTags: ['yomichan'], ankiCardTags: ['yomichan'],
sentenceExtent: 200, sentenceExtent: 200,
@ -64,6 +62,10 @@ function sanitizeOptions(options) {
} }
} }
if (options.ankiMethod === 'ankiweb') {
options.ankiMethod = 'disabled';
}
return options; return options;
} }

View File

@ -95,9 +95,6 @@ class Yomichan {
this.options = options; this.options = options;
switch (options.ankiMethod) { switch (options.ankiMethod) {
case 'ankiweb':
this.anki = new AnkiWeb(options.ankiUsername, options.ankiPassword);
break;
case 'ankiconnect': case 'ankiconnect':
this.anki = new AnkiConnect(); this.anki = new AnkiConnect();
break; break;

View File

@ -128,9 +128,8 @@
<p class="help-block"> <p class="help-block">
Yomichan features automatic flashcard creation for <a href="http://ankisrs.net/">Anki</a>, a free application Yomichan features automatic flashcard creation for <a href="http://ankisrs.net/">Anki</a>, a free application
designed to help you retain knowledge. While the <a href="https://foosoft.net/projects/anki-connect/">AnkiConnect</a> plugin designed to help you retain knowledge. This functionality requires prior installation of the
offers the best experience, it is also possible to create flashcards through <a href="https://ankiweb.net/">AnkiWeb</a>, <a href="https://foosoft.net/projects/anki-connect/">AnkiConnect</a> plugin.
provided you already have an account.
</p> </p>
<div class="alert alert-danger" id="anki-error"> <div class="alert alert-danger" id="anki-error">
@ -143,23 +142,10 @@
<select class="form-control" id="anki-method"> <select class="form-control" id="anki-method">
<option value="disabled">Disabled (no auto flashcard creation)</option> <option value="disabled">Disabled (no auto flashcard creation)</option>
<option value="ankiconnect">AnkiConnect (requires the AnkiConnect plugin)</option> <option value="ankiconnect">AnkiConnect (requires the AnkiConnect plugin)</option>
<option value="ankiweb">AnkiWeb (requires an account on AnkiWeb)</option>
</select> </select>
</div> </div>
<div id="anki-general"> <div id="anki-general">
<div class="row">
<div class="form-group anki-login col-xs-6">
<label for="anki-username">Username</label>
<input type="text" id="anki-username" class="form-control anki-credential">
</div>
<div class="form-group anki-login col-xs-6">
<label for="anki-password">Password</label>
<input type="password" id="anki-password" class="form-control anki-credential">
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="anki-card-tags">Card tags (comma or space separated)</label> <label for="anki-card-tags">Card tags (comma or space separated)</label>
<input type="text" id="anki-card-tags" class="form-control"> <input type="text" id="anki-card-tags" class="form-control">

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Yomichan", "name": "Yomichan",
"version": "1.0.1", "version": "1.0.3",
"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"},
@ -25,11 +25,8 @@
"page": "bg/options.html" "page": "bg/options.html"
}, },
"permissions": [ "permissions": [
"webRequest",
"webRequestBlocking",
"file://*/*", "file://*/*",
"http://127.0.0.1/*", "http://127.0.0.1/*",
"https://ankiweb.net/*",
"storage" "storage"
], ],
"web_accessible_resources": [ "web_accessible_resources": [