aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-10-30 13:01:06 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 17:43:30 +0200
commit627e16d44b19bdae1bc51fa6f76bc766939e0786 (patch)
tree49efafc8c712dc535027228f0be1b92bf85f6c20
parent530b95895bb8a807cbaea6a324323c49152c16ab (diff)
improve text preview
-rw-r--r--ext/bg/js/search-query-parser.js26
1 files changed, 20 insertions, 6 deletions
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);
}