From ce1a862df41691da1ee0c0d86b2fdb16472f316b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 31 Aug 2021 20:45:29 -0400 Subject: Fix empty sentence on some search page URLs (#1919) --- ext/js/display/display-anki.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'ext/js/display') 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}; } -- cgit v1.2.3