From 2f74b3659b3aac4bd9bccee705f1b972a5332f4d Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 29 Jan 2023 19:33:36 +0100 Subject: highlight selected word in sentence when copying --- yomichan-user/conf.d/sentence-export.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'yomichan-user/conf.d') 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; } } -- cgit v1.2.3