mclemente / fvtt-module-polyglot

Talk to others using a language you can speak and scrambles text you can't understand.
MIT License
40 stars 47 forks source link

Support for scrambling messages with HTML in them #345

Closed K4rakara closed 5 months ago

K4rakara commented 5 months ago

Is your feature request related to a problem? Please describe. When composing messages, it's often helpful to use bold and italics to add tonal information. This can be done through a markdown module such as df-chat-enhance, or alternatively by writing simple HTML directly into the message editor, such as <b>Hello world</b>. Currently, it appears that Polyglot is skipping messages that contain any HTML content. I haven't checked the source code to verify this assumption, but given the consistent behavior, I'm fairly certain of it.

Describe the solution you'd like First off- I don't think its feasible or necessary to apply the HTML tags to the scrambled version of messages. After all, it wouldn't make much sense to. If you don't understand a foreign language, you're likely going to have a hard time discerning tonal indicators that may be used by native speakers. So, to solve this, I'd to about it via one of two ways:

  1. If Polyglot is scrambling messages before they've been committed to the HTML, I'd simply use the browsers DOMParser API on the message text, then extract the text that should be scrambled via .body.innerText on the returned HTMLDocument.
    1. If Polyglot is scrambling messages after they've been committed to the HTML, then simply use a property like .innerText on the DOM node. However, this approach would have some unintended side effects- for example, I'm working on a chat enhancement module to replace df-chat-enhance, and it appends <span class="karakara-chat-enhancements edited">(edited)</span> to messages that have been edited. Since Polyglot would be getting the text from the .innerText property, it would include this edited marker in the text to be scrambled.

Additional context I'd be willing to implement this feature myself, so long as it would be accepted.

mclemente commented 5 months ago

You are correct, it ignores text that starts with a <. It's a leftover from 2021 when links in a ChatMessage.content started with anchors (<a) and Polyglot mistankenly scrambled them.

Nowadays, links on ChatMessage.content are just plaintext and Polyglot actually checks for things like @ and :// instead, so I think it can start accepting HTML stuff back again.

mclemente commented 5 months ago

Btw I've released a version yesterday that should accept HTML elements now, let me know if that's enough for you to work with so this issue can be closed.

K4rakara commented 5 months ago

I was going to say something about the [object Object] bug, but it seems you've gotten that fixed. Works on my end. Cheers! image