aboutsummaryrefslogtreecommitdiff
path: root/yomichan-user/conf.d
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-29 19:33:36 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-29 19:33:36 +0100
commit2f74b3659b3aac4bd9bccee705f1b972a5332f4d (patch)
treebbba65dc40ea9145ba4ad00dc9d568932e4492e5 /yomichan-user/conf.d
parent657ca0b948fe2915bab056081c5494fe089f7afc (diff)
highlight selected word in sentence when copying
Diffstat (limited to 'yomichan-user/conf.d')
-rw-r--r--yomichan-user/conf.d/sentence-export.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/yomichan-user/conf.d/sentence-export.js b/yomichan-user/conf.d/sentence-export.js
index fb034d1..f15d890 100644
--- a/yomichan-user/conf.d/sentence-export.js
+++ b/yomichan-user/conf.d/sentence-export.js
@@ -20,14 +20,23 @@ async function exportSentence() {
var inputHTML = document.getElementById("query-parser-content");
var output = "";
+ var selection = window.getSelection();
+ // TODO: fix right-to-left selected text
+
for (var child of inputHTML.children) {
for (var subchild of child.childNodes) {
if (subchild.nodeName == '#text') {
- output += subchild.textContent;
+ for (var i in subchild.textContent) {
+ if (selection.anchorNode == subchild && i == selection.anchorOffset) output += "*";
+ output += subchild.textContent[i];
+ if (selection.focusNode == subchild && i == selection.focusOffset - 1) output += "*";
+ }
continue;
}
if (subchild.nodeName == 'RUBY') {
+ if (selection.anchorNode.parentNode.parentNode == subchild) output += "*";
output += `[${subchild.childNodes[0].innerText}](${subchild.childNodes[1].innerText})`;
+ if (selection.focusNode.parentNode.parentNode == subchild) output += "*";
continue;
}
}