improve text preview

This commit is contained in:
siikamiika 2019-10-30 13:01:06 +02:00
parent 530b95895b
commit 627e16d44b

View File

@ -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) {
if (furigana) {
const rubyElement = document.createElement('ruby');
const furiganaElement = document.createElement('rt');
if (furigana) {
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);
}