Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to bulk generate anki cards #895

Merged
merged 60 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
92c4f12
Add option to bulk generate anki cards
Kuuuube May 8, 2024
4e46589
Fix tab replacement
Kuuuube May 8, 2024
c47865c
Set deckname and modelname in note builder
Kuuuube May 9, 2024
cbf23a9
Add addNotes to ankiconnect api implementation
Kuuuube May 9, 2024
e35c33a
Add option to send word list to anki directly
Kuuuube May 9, 2024
0eb52d1
Add support for audio and media toggle
Kuuuube May 9, 2024
55074fe
Add support for dictionary media
Kuuuube May 9, 2024
edce401
Remove unnecessary assignment
Kuuuube May 9, 2024
967fb6d
Remove unused css
Kuuuube May 9, 2024
6728fba
Remove redundant html
Kuuuube May 9, 2024
102d8f6
Start of progress bar implementation
Kuuuube May 9, 2024
3e4f55a
Remove redundant type annotation
Kuuuube May 9, 2024
95a4d80
Remove unused import
Kuuuube May 9, 2024
4e2a6c9
Rename words to terms
Kuuuube May 9, 2024
8e17c4d
Print progress to console
Kuuuube May 9, 2024
9f24395
Add confirmation to Export to file
Kuuuube May 9, 2024
c7a2c88
Improve progress logs
Kuuuube May 9, 2024
df98c76
Add unresponsive and console note
Kuuuube May 9, 2024
414fc53
Add progress bars
Kuuuube May 9, 2024
fea1b6d
Make cancel button actually cancel operation
Kuuuube May 9, 2024
6a3a04b
Remove unresponsive warnings
Kuuuube May 9, 2024
dd59fb8
Disable send and export buttons after they are clicked
Kuuuube May 9, 2024
14a5172
Merge branch 'master' into bulk-card-creation
Kuuuube May 9, 2024
5d92b1d
Remove unneeded Yomichan mention
Kuuuube May 9, 2024
e39e646
Mark as experimental
Kuuuube May 9, 2024
41f49b1
Clarify description
Kuuuube May 9, 2024
7d79253
Add documentation on Anki Deck Generation
Kuuuube May 10, 2024
b8646ea
Add experimental note in docs
Kuuuube May 10, 2024
b13076b
Add warning text to settings page
Kuuuube May 10, 2024
6c635b9
Switch example text based on language
Kuuuube May 10, 2024
b18d3e5
Remove silly cancel function and bind directly
Kuuuube May 10, 2024
b4025e7
Rename to model
Kuuuube May 10, 2024
30a322e
Add link to docs
Kuuuube May 10, 2024
04fde9a
Make test text less confusing
Kuuuube May 10, 2024
cd8b726
Rename deck to notes
Kuuuube May 10, 2024
daa8efa
Clarify what is being sent to anki
Kuuuube May 10, 2024
68c68f1
Fix incorrect modal header text
Kuuuube May 10, 2024
a0b6d90
Clarify wording
Kuuuube May 10, 2024
b658a23
Fix ankiconnect addNotes return types
Kuuuube May 10, 2024
7eaf16b
Add error handling to send to anki
Kuuuube May 10, 2024
ccf14f8
Fix wording and naming in docs
Kuuuube May 10, 2024
31c53a7
Add option to prevent sending duplicates to anki
Kuuuube May 10, 2024
120bcff
Update anki deck and model without a page refresh
Kuuuube May 10, 2024
9c7d62e
Cleanup internal html naming
Kuuuube May 10, 2024
babc9a8
Cleanup type definition styling
Kuuuube May 10, 2024
5b464d9
Update example text without a page refresh
Kuuuube May 10, 2024
34bd779
Prevent closing the send/export confirm modal from messing up the ui …
Kuuuube May 10, 2024
a118ea7
Fix cancel getting stuck on true
Kuuuube May 10, 2024
bb447d0
Merge branch 'master' into bulk-card-creation
Kuuuube May 11, 2024
84033dd
Consolidate state changes
Kuuuube May 11, 2024
03d5cc6
Support idle download timeout
Kuuuube May 11, 2024
4eb83ff
Capitalize Failed to add cards error
Kuuuube May 11, 2024
2e7f5ea
Add separate variable for idleTimeout calculation
Kuuuube May 11, 2024
6d9f65a
Remove redundant _cachedDictionaryEntryValue variable
Kuuuube May 11, 2024
091288d
Use tags option to populate tags
Kuuuube May 11, 2024
843550b
Include deck and tags when exporting to file
Kuuuube May 11, 2024
baa0c98
Use date down to seconds and zero pad
Kuuuube May 11, 2024
894dfc8
Remove unnecessary ternary
Kuuuube May 11, 2024
5010ece
Limit 'path' finding function to only being able to search for 'path'
Kuuuube May 12, 2024
aadb1f4
Rename _findPathsByKey to _findAllPaths
Kuuuube May 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/anki-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,38 @@ Below are some troubleshooting tips you can try if you are unable to create new

- If all of the buttons appear grayed out, then you should double-check your deck and model configuration settings.
- If no icons appear at all, make sure that Anki is running in the background and that [AnkiConnect](https://foosoft.net/projects/anki-connect) has been installed.

### Anki Note Generation

Using the `Generate Anki Notes (Experimental)...` feature in the settings page it is possible to easily generate and export large amounts of Anki cards.

> [!WARNING]
> This feature is experimental!

First, get a newline separated list of terms. For example:

```
竜巻
```

Enter this list into the large text box in the `Anki Note Generator` popup window.

Next, select either `Send to Anki` or `Export to File`.

**Send to Anki:**

`Send to Anki` will send all the terms to the active Anki deck using the active Anki model specified on the page. To change the active Anki deck or Anki model, edit them in the `Configure Anki card format...` setting.

Make sure to confirm you are exporting to the correct deck and with the correct Anki model. After the notes are sent to Anki there is no way to automatically undo the changes.

To include media in notes sent to Anki, make sure to enable the `Add media to notes` option. Media includes audio, images, and svgs. Exporting with media may take significantly longer than without it.

To prevent duplicate notes being sent to Anki, enable the `Prevent sending duplicate notes` option. This will check for duplicate notes that already exist. The `Check for duplicates across all models` and `Duplicate card scope` settings are used to determine what is considered a duplicate card. **This does not remove duplicates in the term list.**

**Export to File:**

`Export to File` will export all the terms to an Anki deck file using the active Anki card format specified on the page and in Anki's `Notes in plain text (.txt)` format. After exporting completes you will be prompted to save the file. This file can later be imported into Anki.

Media cannot be included when exporting in this format.
34 changes: 34 additions & 0 deletions ext/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,40 @@ code.anki-field-marker {
min-height: calc(var(--textarea-line-height) * 5 + var(--textarea-padding) * 2);
}

.generate-anki-notes-layout {
display: flex;
flex-flow: column nowrap;
}
.generate-anki-notes-info {
flex: 0 1 auto;
}
.generate-anki-notes-test-container {
flex: 0 1 auto;
}
.generate-anki-notes-test-table {
display: grid;
grid-template-columns: 1fr auto;
grid-template-rows: auto;
align-items: center;
width: 100%;
box-sizing: border-box;
column-gap: 0.85em;
}
.generate-anki-notes-test-table-header {
font-size: var(--font-size-small);
}
#generate-anki-notes-textarea {
flex: 1 1 auto;
width: 100%;
max-width: 100%;
box-sizing: border-box;
resize: none;
min-height: calc(var(--textarea-line-height) * 5 + var(--textarea-padding) * 2);
}
#generate-anki-notes-test-text-input {
width: 100%;
}

.code {
flex: 0 0 auto;
width: 100%;
Expand Down
13 changes: 13 additions & 0 deletions ext/js/comm/anki-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ export class AnkiConnect {
return result;
}

/**
* @param {import('anki').Note[]} notes
* @returns {Promise<?((number | null)[] | null)>}
*/
async addNotes(notes) {
if (!this._enabled) { return null; }
await this._checkVersion();
const result = await this._invoke('addNotes', {notes});
if (result !== null && !Array.isArray(result)) {
throw this._createUnexpectedResultError('(number | null)[] | null', result);
}
return result;
}

/**
* @param {import('anki').Note[]} notes
Expand Down
16 changes: 16 additions & 0 deletions ext/js/pages/settings/anki-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,22 @@ export class AnkiController {
return null;
}
}

/**
* @param {import('anki').Note[]} notes
* @returns {Promise<?((number | null)[] | null)>}
*/
async addNotes(notes) {
Kuuuube marked this conversation as resolved.
Show resolved Hide resolved
return await this._ankiConnect.addNotes(notes);
}

/**
* @param {import('anki').Note[]} notes
* @returns {Promise<boolean[]>}
*/
async canAddNotes(notes) {
return await this._ankiConnect.canAddNotes(notes);
}
}

class AnkiCardController {
Expand Down
Loading