wip
This commit is contained in:
parent
3b0aa88de1
commit
9de0d34af3
@ -168,13 +168,13 @@ window.driver = new class {
|
|||||||
} else {
|
} else {
|
||||||
textSource.setEndOffset(length);
|
textSource.setEndOffset(length);
|
||||||
|
|
||||||
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
|
const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt);
|
||||||
const url = window.location.href;
|
const url = window.location.href;
|
||||||
this.popup.showTermDefs(
|
this.popup.showTermDefs(
|
||||||
textSource.getRect(),
|
textSource.getRect(),
|
||||||
definitions,
|
definitions,
|
||||||
this.options,
|
this.options,
|
||||||
{sentence, url}
|
{cloze, url}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lastTextSource = textSource;
|
this.lastTextSource = textSource;
|
||||||
@ -194,13 +194,13 @@ window.driver = new class {
|
|||||||
if (definitions.length === 0) {
|
if (definitions.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
|
const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt);
|
||||||
const url = window.location.href;
|
const url = window.location.href;
|
||||||
this.popup.showKanjiDefs(
|
this.popup.showKanjiDefs(
|
||||||
textSource.getRect(),
|
textSource.getRect(),
|
||||||
definitions,
|
definitions,
|
||||||
this.options,
|
this.options,
|
||||||
{sentence, url}
|
{cloze, url}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lastTextSource = textSource;
|
this.lastTextSource = textSource;
|
||||||
|
@ -152,7 +152,7 @@ function docRangeFromPoint(point, imposter) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function docSentenceExtract(source, extent) {
|
function docClozeExtract(source, extent) {
|
||||||
const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'};
|
const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'};
|
||||||
const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'};
|
const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'};
|
||||||
const terminators = '…。..??!!';
|
const terminators = '…。..??!!';
|
||||||
@ -182,8 +182,8 @@ function docSentenceExtract(source, extent) {
|
|||||||
|
|
||||||
quoteStack = [];
|
quoteStack = [];
|
||||||
|
|
||||||
let endPos = content.length;
|
let endPos = content.length - 1;
|
||||||
for (let i = position; i < endPos; ++i) {
|
for (let i = position; i <= endPos; ++i) {
|
||||||
const c = content[i];
|
const c = content[i];
|
||||||
|
|
||||||
if (quoteStack.length === 0) {
|
if (quoteStack.length === 0) {
|
||||||
@ -204,5 +204,15 @@ function docSentenceExtract(source, extent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return content.substring(startPos, endPos).trim();
|
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);
|
||||||
|
|
||||||
|
return {
|
||||||
|
sentence: sentence.trim(),
|
||||||
|
prefix: clozePrefix.trim(),
|
||||||
|
body: clozeBody.trim(),
|
||||||
|
sufix: clozeSuffix.trim()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user