Run JavaScript on selected text

Thank you all for the suggestions.

I don’t want to take on a whole new project rewriting it in TW script.
For now, I’m putting it in an iframe - at least saves me from going to another browser window. (for now the iframe content source is an external file; working on how to have html in a tiddler and use it to call iframe)

Next problem is how do I send a selection of text to the iframe? I’ve read about the tm-edit-text-operations but can’t quite figure out how to make the connection.

p.s. I came across the context-menu-plugin but don’t know how to adapt it to my situation. thread. plugin.