aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display/display-anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-08-31 20:45:29 -0400
committerGitHub <noreply@github.com>2021-08-31 20:45:29 -0400
commitce1a862df41691da1ee0c0d86b2fdb16472f316b (patch)
tree6a94005546dee97f9bf5db9ab18cdc0ababdfae0 /ext/js/display/display-anki.js
parent3e7f3af63c01e39577bdc548d0dc81e83020df78 (diff)
Fix empty sentence on some search page URLs (#1919)
Diffstat (limited to 'ext/js/display/display-anki.js')
-rw-r--r--ext/js/display/display-anki.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js
index ee3ca68d..8a023382 100644
--- a/ext/js/display/display-anki.js
+++ b/ext/js/display/display-anki.js
@@ -216,13 +216,14 @@ class DisplayAnki {
if (typeof url !== 'string') {
url = window.location.href;
}
- sentence = this._getValidSentenceData(sentence);
+ const {query, fullQuery} = this._display;
+ sentence = this._getValidSentenceData(sentence, query);
return {
url,
sentence,
documentTitle,
- query: this._display.query,
- fullQuery: this._display.fullQuery
+ query,
+ fullQuery
};
}
@@ -563,10 +564,14 @@ class DisplayAnki {
return isTerms ? ['term-kanji', 'term-kana'] : ['kanji'];
}
- _getValidSentenceData(sentence) {
+ _getValidSentenceData(sentence, fallback) {
let {text, offset} = (isObject(sentence) ? sentence : {});
- if (typeof text !== 'string') { text = ''; }
- if (typeof offset !== 'number') { offset = 0; }
+ if (typeof text !== 'string') {
+ text = fallback;
+ offset = 0;
+ } else {
+ if (typeof offset !== 'number') { offset = 0; }
+ }
return {text, offset};
}