diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-01-29 19:33:36 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-01-29 19:33:36 +0100 |
commit | 2f74b3659b3aac4bd9bccee705f1b972a5332f4d (patch) | |
tree | bbba65dc40ea9145ba4ad00dc9d568932e4492e5 /yomichan-user | |
parent | 657ca0b948fe2915bab056081c5494fe089f7afc (diff) |
highlight selected word in sentence when copying
Diffstat (limited to 'yomichan-user')
-rw-r--r-- | yomichan-user/conf.d/sentence-export.js | 11 |
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; } } |