ttu-ttu / ebook-reader

Online e-book reader that supports Yomichan
https://reader.ttsu.app
BSD 3-Clause "New" or "Revised" License
698 stars 64 forks source link

compatibility issue with chrome highlight extension #199

Open sapjax opened 1 year ago

sapjax commented 1 year ago

I'm currently developing a chrome extension, which highlights some English words in the text, there is a compatibility issue.

the highlight function replaces the word with an HTML tag, for example, a sentence like:

<p>Imgbot is a friendly robot that optimizes your images and saves you time.</p>

may be replaced by

<p>Imgbot is a friendly robot that <mark>optimizes</mark> your images and saves you time.</p>

The problem is that the ebook-reader's code keeps the text nodes reference in the js memory: https://github.com/ttu-ttu/ebook-reader/blob/4c76cda75201b085d8511e8681b3dce0c5912918/apps/web/src/lib/components/book-reader/book-reader-continuous/character-stats-calculator.ts#L32

and use the references later: https://github.com/ttu-ttu/ebook-reader/blob/4c76cda75201b085d8511e8681b3dce0c5912918/apps/web/src/lib/components/book-reader/book-reader-continuous/character-stats-calculator.ts#L60

but after the extension replaced the text, the paragraph text node does not exist anymore, so when it runs into range.selectNode(node); will throw out an error, and the page renders nothing.

I think we can make some changes here to avoid such compatibility issues with extension.

what do you think?

Renji-XD commented 1 year ago

Hi,

In context of #21 there will probably some changes introduced - we will try to keep this one in mind for it (though i don't know when it may will be taken up) and therefore i will leave it open