Skip to content

Commit

Permalink
Add the ability to choose which dictionary definition you use the aud…
Browse files Browse the repository at this point in the history
…io from or import to Anki
  • Loading branch information
Garethp committed Jul 27, 2020
1 parent a31e522 commit c3e3c58
Show file tree
Hide file tree
Showing 10 changed files with 1,447 additions and 1,101 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Changelog

### Version 1.3.4
* Adds the ability to select which dictionary definition you want to import or hear the audio of (#13)
* Fixes missing audio files form LanguagePod (#6)

### Version 1.3.3
Expand Down
74 changes: 53 additions & 21 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h4><b>Keymap</b></h4>
<label class="my1-1 mr-2" for="keymap-toggleEpwingMode">Toggle Epwing Mode</label>
</div>
<div class="col-3">
<input type="text" class="form-control keymap-input" id="keymap-toggleEpwingMode" />
<input type="text" class="form-control keymap-input" id="keymap-toggleEpwingMode"/>
</div>
</div>
<div class="row">
Expand Down Expand Up @@ -165,6 +165,20 @@ <h4><b>Keymap</b></h4>
<div class="col-3"><input type="text" class="form-control keymap-input"
id="keymap-selectNextDictionary"/></div>
</div>

<div class="row">
<div class="col-4"><label class="my-1 mr-2" for="keymap-nextDefinition">Select Next
Definition</label></div>
<div class="col-3"><input type="text" class="form-control keymap-input"
id="keymap-nextDefinition"/></div>
</div>

<div class="row">
<div class="col-4"><label class="my-1 mr-2" for="keymap-previousDefinition">Select Previous
Definition</label></div>
<div class="col-3"><input type="text" class="form-control keymap-input"
id="keymap-previousDefinition"/></div>
</div>
</form>
</div>
<div class="tab-pane fade" id="dictionaries" role="tabpanel" aria-labelledby="dictionaries-tab">
Expand Down Expand Up @@ -236,49 +250,61 @@ <h4><b>Dictionaries</b></h4>
<div class="tab-pane fade" id="kanji-dictionary" role="tabpanel" aria-labelledby="kanji-dictionary-tab">
<div class="row">
<div class="col-3"><label for="kanjiComponents">Kanji Components</label></div>
<div class="col-3"><input type="checkbox" id="kanjiComponents" data-config-option="showKanjiComponents" /></div>
<div class="col-3"><input type="checkbox" id="kanjiComponents"
data-config-option="showKanjiComponents"/></div>

<div class="col-3"><label for="kanjiHalpern">Halpern</label></div>
<div class="col-3"><input type="checkbox" id="kanjiHalpern" data-config-option="showKanjiHalpern"/></div>
<div class="col-3"><input type="checkbox" id="kanjiHalpern" data-config-option="showKanjiHalpern"/>
</div>

<div class="col-3"><label for="kanjiHeisig">Heisig</label></div>
<div class="col-3"><input type="checkbox" id="kanjiHeisig" data-config-option="showKanjiHeisig"/></div>

<div class="col-3"><label for="kanjiHenshall">Henshall</label></div>
<div class="col-3"><input type="checkbox" id="kanjiHenshall" data-config-option="showKanjiHenshall"/></div>
<div class="col-3"><input type="checkbox" id="kanjiHenshall" data-config-option="showKanjiHenshall"/>
</div>

<div class="col-3"><label for="kanjiLearnersDictionary">Kanji Learners Dictionary</label></div>
<div class="col-3"><input type="checkbox" id="kanjiLearnersDictionary" data-config-option="showKanjiLearnersDictionary" /></div>
<div class="col-3"><input type="checkbox" id="kanjiLearnersDictionary"
data-config-option="showKanjiLearnersDictionary"/></div>

<div class="col-3"><label for="kanjiNelson">Nelson</label></div>
<div class="col-3"><input type="checkbox" id="kanjiNelson" data-config-option="showKanjiNelson" /></div>
<div class="col-3"><input type="checkbox" id="kanjiNelson" data-config-option="showKanjiNelson"/></div>

<div class="col-3"><label for="kanjiNewNelson">New Nelson</label></div>
<div class="col-3"><input type="checkbox" id="kanjiNewNelson" data-config-option="showKanjiNewNelson" /></div>
<div class="col-3"><input type="checkbox" id="kanjiNewNelson" data-config-option="showKanjiNewNelson"/>
</div>

<div class="col-3"><label for="kanjiPinYin">PinYin</label></div>
<div class="col-3"><input type="checkbox" id="kanjiPinYin" data-config-option="showKanjiPinYin" /></div>
<div class="col-3"><input type="checkbox" id="kanjiPinYin" data-config-option="showKanjiPinYin"/></div>

<div class="col-3"><label for="kanjiSkipPattern">Skip Pattern</label></div>
<div class="col-3"><input type="checkbox" id="kanjiSkipPattern" data-config-option="showKanjiSkipPattern" /></div>
<div class="col-3"><input type="checkbox" id="kanjiSkipPattern"
data-config-option="showKanjiSkipPattern"/></div>

<div class="col-3"><label for="kanjiTurtleAndKana">Turtle Kanji & Kana</label></div>
<div class="col-3"><input type="checkbox" id="kanjiTurtleAndKana" data-config-option="showKanjiTurtleAndKana"/></div>
<div class="col-3"><input type="checkbox" id="kanjiTurtleAndKana"
data-config-option="showKanjiTurtleAndKana"/></div>

<div class="col-3"><label for="kanjiTurtleDictionary">Turtle Dictionary</label></div>
<div class="col-3"><input type="checkbox" id="kanjiTurtleDictionary" data-config-option="showKanjiTurtleDictionary" /></div>
<div class="col-3"><input type="checkbox" id="kanjiTurtleDictionary"
data-config-option="showKanjiTurtleDictionary"/></div>

<div class="col-3"><label for="kanjiUnicode">Unicode</label></div>
<div class="col-3"><input type="checkbox" id="kanjiUnicode" data-config-option="showKanjiUnicode" /></div>
<div class="col-3"><input type="checkbox" id="kanjiUnicode" data-config-option="showKanjiUnicode"/>
</div>
</div>
</div>
<div class="tab-pane fade" id="epwing" role="tabpanel" aria-labelledby="epwing-tab">
<h4><b>Installing Epwing</b></h4>
To install epwing, please download and extract <a href="https://github.com/Garethp/epwing-lookup/raw/master/epwing.zip">zip file</a>, then run the
install script for your operating system. It doesn't copy any executables to any directories, so you need to keep the folder where it is.
If you accidentally move or delete the folder, just get the zip again, extract to the desired location and re-run the install script.
To install epwing, please download and extract <a
href="https://github.com/Garethp/epwing-lookup/raw/master/epwing.zip">zip file</a>, then run the
install script for your operating system. It doesn't copy any executables to any directories, so you need to
keep the folder where it is.
If you accidentally move or delete the folder, just get the zip again, extract to the desired location and
re-run the install script.

<hr />
<hr/>
<form class="form-group">
<div class="row">
<div class="col-3">
Expand All @@ -299,13 +325,13 @@ <h4><b>Keymap</b></h4>
<label class="my1-1 mr-2" for="keymap-epwingPreviousEntry">Previous Entry</label>
</div>
<div class="col-3">
<input type="text" class="form-control keymap-input" id="keymap-epwingPreviousEntry" />
<input type="text" class="form-control keymap-input" id="keymap-epwingPreviousEntry"/>
</div>
<div class="col-3">
<label class="my1-1 mr-2" for="keymap-epwingNextEntry">Next Entry</label>
</div>
<div class="col-3">
<input type="text" class="form-control keymap-input" id="keymap-epwingNextEntry" />
<input type="text" class="form-control keymap-input" id="keymap-epwingNextEntry"/>
</div>
</div>
</div>
Expand Down Expand Up @@ -374,6 +400,7 @@ <h4><b>Keymap</b></h4>
<div class="tab-pane fade" id="changelog" role="tabpanel" aria-labelledby="changelog-tab">
<h4>Version 1.3.4</h4>
<ul>
<li>Adds the ability to select which dictionary definition you want to import or hear the audio of</li>
<li>Fixes missing audio from Language Pod</li>
</ul>

Expand All @@ -394,7 +421,9 @@ <h4>Version 1.3.1</h4>

<h4>Version 1.3.0</h4>
<ul>
<li>Added a VN Hook page. While the page is open, it'll monitor your clipboard for you and automatically add items copied to the page</li>
<li>Added a VN Hook page. While the page is open, it'll monitor your clipboard for you and automatically
add items copied to the page
</li>
</ul>

<h4>Version 1.2.2</h4>
Expand Down Expand Up @@ -433,7 +462,9 @@ <h4>Version 1.1.4</h4>
<h4>Version 1.1.3</h4>
<ul>
<li>Included support for Typescript by including Webpack. Hopefully won't cause issues</li>
<li>Fixed annoying bug where the icon wouldn't reset on start, making the icon look like it was enabled when it wasn't</li>
<li>Fixed annoying bug where the icon wouldn't reset on start, making the icon look like it was enabled
when it wasn't
</li>
</ul>

<h4>Version 1.1.2</h4>
Expand All @@ -443,7 +474,8 @@ <h4>Version 1.1.2</h4>

<h4>Version 1.1.1</h4>
<ul>
<li>Fixing Epwing popup showing constantly, because of course I'd forget to fix that before releasing</li>
<li>Fixing Epwing popup showing constantly, because of course I'd forget to fix that before releasing
</li>
</ul>

<h4>Version 1.1.0</h4>
Expand Down
12 changes: 9 additions & 3 deletions src/AnkiImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ export default class AnkiImport {
return Promise.all(promises);
}

async downloadAudio(entry: SearchResults) {
async downloadAudio(entry: SearchResults & { selected?: number }) {
if (!isDictionaryResult(entry)) return;
if (!entry?.data) return;
if (await AudioPlayer.isNoAudio(entry)) return;

const selected = entry.selected || 0;

const audioUrl = AudioPlayer.getAudioUrl(entry);

let [, dictionaryForm, reading] = entry.data[0][0].match(
let [, dictionaryForm, reading] = entry.data[selected][0].match(
/^(.+?)\s+(?:\[(.*?)\])?\s*\/(.+)\//
);

Expand All @@ -124,13 +126,15 @@ export default class AnkiImport {
}

// entry = Contains the work lookup info (kana, kanji, def)
// selected = The index of the entry to look up
// word = Highlighted Word
// sentence = The sentence containing the highlighted word
// sentenceWBlank = Like sentence except the highlighted word is replaced with blanks
// saveKana = Replace kanji with kana (that is, $d=$r)
// saveFormat = Token-based save format
static async makeTextOptions(
entry: SearchResults,
selected: number,
word: string,
sentence: string,
sentenceWithBlank: string,
Expand Down Expand Up @@ -159,7 +163,9 @@ export default class AnkiImport {
// entryData[2] = kana (null if no kanji)
// entryData[3] = definition

entryData = entry.data[0][0].match(/^(.+?)\s+(?:\[(.*?)\])?\s*\/(.+)\//);
entryData = entry.data[selected][0].match(
/^(.+?)\s+(?:\[(.*?)\])?\s*\/(.+)\//
);
let [_, dictionaryForm, reading, definition] = entryData;

// Does the user want to use the reading in place of kanji for the $d token?
Expand Down
7 changes: 4 additions & 3 deletions src/AudioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import Utils from "./Utils";
import {isKanjiResult, SearchResults} from "./interfaces/SearchResults";

export default class AudioPlayer {
static getAudioUrl(entry: SearchResults): string {
static getAudioUrl(entry: SearchResults & { selected?: number }): string {
let kanaText;
let kanjiText;
const selected = entry.selected || 0;

//We have a single kanji selected
if (isKanjiResult(entry)) {
Expand All @@ -18,8 +19,8 @@ export default class AudioPlayer {
kanaText = Utils.convertKatakanaToHirigana(kanaText).kana;

if (!kanaText) return;
} else if (entry.data[0]) {
let entryData = entry.data[0][0].match(
} else if (entry.data[selected]) {
let entryData = entry.data[selected][0].match(
/^(.+?)\s+(?:\[(.*?)\])?\s*\/(.+)\//
);

Expand Down
2 changes: 2 additions & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class RikaiController {
async sendToAnki(content) {
const {
entry,
selected,
word,
sentence,
sentenceWithBlank,
Expand All @@ -125,6 +126,7 @@ export class RikaiController {
} = content;
const entryFormat = await AnkiImport.makeTextOptions(
entry,
selected || 0,
word,
sentence,
sentenceWithBlank,
Expand Down
Loading

0 comments on commit c3e3c58

Please sign in to comment.