From 627e16d44b19bdae1bc51fa6f76bc766939e0786 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Wed, 30 Oct 2019 13:01:06 +0200 Subject: improve text preview --- ext/bg/js/search-query-parser.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index c3a3900b..9bea6508 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -59,25 +59,39 @@ class QueryParser { } async setText(text) { + this.queryParser.innerHTML = ''; this.search.setSpinnerVisible(true); + let previewText = text; + while (previewText) { + const tempText = previewText.slice(0, 2); + previewText = previewText.slice(2); + + const tempRuby = document.createElement('ruby'); + const tempFurigana = document.createElement('rt'); + tempRuby.appendChild(document.createTextNode(tempText)); + tempRuby.appendChild(tempFurigana); + this.queryParser.appendChild(tempRuby); + } + const results = await apiTextParse(text, this.search.getOptionsContext()); - const tempContainer = document.createElement('div'); + const textContainer = document.createElement('div'); for (const {text, furigana} of results) { + const rubyElement = document.createElement('ruby'); + const furiganaElement = document.createElement('rt'); if (furigana) { - const rubyElement = document.createElement('ruby'); - const furiganaElement = document.createElement('rt'); furiganaElement.innerText = furigana; rubyElement.appendChild(document.createTextNode(text)); rubyElement.appendChild(furiganaElement); - tempContainer.appendChild(rubyElement); } else { - tempContainer.appendChild(document.createTextNode(text)); + rubyElement.appendChild(document.createTextNode(text)); + rubyElement.appendChild(furiganaElement); } + textContainer.appendChild(rubyElement); } this.queryParser.innerHTML = ''; - this.queryParser.appendChild(tempContainer); + this.queryParser.appendChild(textContainer); this.search.setSpinnerVisible(false); } -- cgit v1.2.3