summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-11-08 16:25:07 -0500
committerGitHub <noreply@github.com>2020-11-08 16:25:07 -0500
commit16321a1f8c9902be100b01067e1593694fa51341 (patch)
tree2cb25c4fe0447e58c91338cdce69e7b370518d25 /ext
parent4e3040941038acc4f739e4077aee14cb64d3aa81 (diff)
Add duplicate check option (#1012)
* Add anki.checkForDuplicates option * Use checkForDuplicates for button display * Add property to card creation
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/data/options-schema.json5
-rw-r--r--ext/bg/js/anki-note-builder.js2
-rw-r--r--ext/bg/js/options.js4
-rw-r--r--ext/bg/settings.html5
-rw-r--r--ext/mixed/js/display.js28
5 files changed, 41 insertions, 3 deletions
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json
index 159ca009..edb30074 100644
--- a/ext/bg/data/options-schema.json
+++ b/ext/bg/data/options-schema.json
@@ -671,6 +671,7 @@
"terms",
"kanji",
"duplicateScope",
+ "checkForDuplicates",
"fieldTemplates"
],
"properties": {
@@ -771,6 +772,10 @@
"default": "collection",
"enum": ["collection", "deck", "deck-root"]
},
+ "checkForDuplicates": {
+ "type": "boolean",
+ "default": true
+ },
"fieldTemplates": {
"type": ["string", "null"],
"default": null
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js
index aa76ecd9..4ac597da 100644
--- a/ext/bg/js/anki-note-builder.js
+++ b/ext/bg/js/anki-note-builder.js
@@ -31,6 +31,7 @@ class AnkiNoteBuilder {
context,
templates,
tags=[],
+ checkForDuplicates=true,
duplicateScope='collection',
resultOutputMode='split',
compactGlossaries=false,
@@ -60,6 +61,7 @@ class AnkiNoteBuilder {
deckName: deck,
modelName: model,
options: {
+ allowDuplicate: !checkForDuplicates,
duplicateScope,
duplicateScopeOptions: {
deckName: duplicateScopeDeckName,
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 0edbb82a..bb90e655 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -613,8 +613,12 @@ class OptionsUtil {
// Version 6 changes:
// Updated handlebars templates to include "conjugation" definition.
// Added global option showPopupPreview.
+ // Added anki.checkForDuplicates.
await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v6.handlebars');
options.global.showPopupPreview = false;
+ for (const profile of options.profiles) {
+ profile.options.anki.checkForDuplicates = true;
+ }
return options;
}
}
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index 67a2d75c..6ec89269 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -922,6 +922,11 @@
</div>
<div class="form-group options-advanced">
+ <label>Duplicates</label><br>
+ <label style="font-weight: normal;"><input type="checkbox" data-setting="anki.checkForDuplicates"> Check for duplicate cards</label><br>
+ </div>
+
+ <div class="form-group options-advanced">
<label for="duplicate-scope">Duplicate scope</label>
<select class="form-control" id="duplicate-scope" data-setting="anki.duplicateScope">
<option value="collection">Collection</option>
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 33d8f986..07e4f37a 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -901,8 +901,15 @@ class Display extends EventDispatcher {
const modes = isTerms ? ['term-kanji', 'term-kana'] : ['kanji'];
let states;
try {
- const noteContext = await this._getNoteContext();
- states = await this._areDefinitionsAddable(definitions, modes, noteContext);
+ if (this._options.anki.checkForDuplicates) {
+ const noteContext = await this._getNoteContext();
+ states = await this._areDefinitionsAddable(definitions, modes, noteContext);
+ } else {
+ if (!await api.isAnkiConnected()) {
+ throw new Error('Anki not connected');
+ }
+ states = this._areDefinitionsAddableForcedValue(definitions, modes, true);
+ }
} catch (e) {
return;
}
@@ -1377,10 +1384,24 @@ class Display extends EventDispatcher {
return results;
}
+ _areDefinitionsAddableForcedValue(definitions, modes, canAdd) {
+ const results = [];
+ const definitionCount = definitions.length;
+ const modeCount = modes.length;
+ for (let i = 0; i < definitionCount; ++i) {
+ const modeArray = [];
+ for (let j = 0; j < modeCount; ++j) {
+ modeArray.push({canAdd, noteIds: null});
+ }
+ results.push(modeArray);
+ }
+ return results;
+ }
+
async _createNote(definition, mode, context, options, templates, injectMedia) {
const {
general: {resultOutputMode, compactGlossaries},
- anki: {tags, duplicateScope, kanji, terms, screenshot: {format, quality}},
+ anki: {tags, checkForDuplicates, duplicateScope, kanji, terms, screenshot: {format, quality}},
audio: {sources, customSourceUrl}
} = options;
const modeOptions = (mode === 'kanji') ? kanji : terms;
@@ -1416,6 +1437,7 @@ class Display extends EventDispatcher {
context,
templates,
tags,
+ checkForDuplicates,
duplicateScope,
resultOutputMode,
compactGlossaries,