yomichan
yomichan copied to clipboard
Copy and paste text with furigana in Chrome
I found that in Chrome when some text with furigana is copied, furigana will be copied as well
On search page
飛び移って -> 飛とび移うつって when copied and pasted
Same thing happens in dictionary entries
飛び移る -> 飛とび移うつる
However, in Firefox, furigana are ignored when text is copied
飛び移る -> 飛び移る
Would it be possible to copy text without furigana being copied in Chrome? Am I missing something obvious?
That's a browser difference that is unrelated to Yomichan.
飛び移る
The best you'll able to do with Yomichan is to add this custom CSS rule:
rt {
user-select: none;
}
but that will only affect text inside Yomichan's search/popup page.
Thanks for the help. I tried the CSS rule but this problem occurs #1152.
I guess I will just use Firefox then. It is easier for me to copy and paste word for look up.
The issue described in #1152 should be fixed in the latest release. If you describe the issue you're seeing, I can take a look at that also; the additional CSS rule should not affect behaviour.
Maybe this is just my problem but when I added the additional CSS rule , the issue #1152 occurred, it went back to normal if I removed the CSS rule. Thanks again for the help for an issue unrelated to Yomichan. I think I can just use Firefox, it works very well for my usage.
I am experiencing the same issue here as well.
A fix can be implemented by intercepting the copy event, hiding the kana, then copying the content, then re-showing the kana. I've written an extension to do this on some sites, but I think it would have to be done within the Yomichan extension itself to work in this case, and probably gated with a user setting because sometimes folks probably intend to copy the kana 🤔
If anyone more familiar with the codebase could point me at a good location to try adding this within the project, I'd be happy to try and hack something together myself 🤷🏻
document.addEventListener("copy", (event) => {
// 1. Hide furigana
const furigana = document.querySelectorAll(".furigana, .dc-hiragana, .fg, rt");
if (furigana[0]) {
Array.from(furigana, (f) => { f.style.display = "none" });
}
// 2. Get selection
const selection = document.getSelection();
let textToCopy = selection.toString().trim();
// 3. Remove line breaks from array
const lineBreaks = /(\r\n|\n|\r)/gm;
textToCopy = textToCopy
.split(lineBreaks)
.filter((item) => !item.match(lineBreaks))
.join("");
// 4. Re-show furigana if they were hidden
if (furigana[0]) {
Array.from(furigana, (f) => { f.style.display = "" });
}
event.clipboardData.setData("text/plain", textToCopy);
event.preventDefault();
});