Better output
This commit is contained in:
parent
70faa9e87f
commit
2bdb576378
@ -48,8 +48,16 @@ class Client {
|
||||
return;
|
||||
}
|
||||
|
||||
findTerm(range.toString(), ({results, length}) => {
|
||||
if (length === 0) {
|
||||
this.hidePopup();
|
||||
} else {
|
||||
range.setEnd(range.endContainer, range.startOffset + length);
|
||||
this.popup.html(renderDefs(results.slice(0, 5)));
|
||||
this.showPopup(range);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMessage(request, sender, callback) {
|
||||
this.setEnabled(request === 'enabled');
|
||||
|
20
ext/util.js
20
ext/util.js
@ -68,3 +68,23 @@ function getPopupPositionForRange(popup, range, offset) {
|
||||
|
||||
return {x: posX, y: posY};
|
||||
}
|
||||
|
||||
function renderDefs(terms) {
|
||||
const outputs = [];
|
||||
for (let term of terms) {
|
||||
outputs.push(renderDef(term));
|
||||
}
|
||||
|
||||
return outputs.join('');
|
||||
}
|
||||
|
||||
function renderDef(term) {
|
||||
return `
|
||||
<div class="yomichan-def">
|
||||
<span class="yomichan-def-expression">${term.expression}</span>
|
||||
<span class="yomichan-def-rules">${term.rules.join(' < ')}</span>
|
||||
<span class="yomichan-def-reading">${term.reading}</span>
|
||||
<span class="yomichan-def-glossary">${term.glossary}</span>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user