cschiller / zhongwen

Official source code of the "Zhongwen" Chrome extension
https://chrome.google.com/webstore/detail/zhongwen-chinese-english/kkmlkkjojmombglmlpbpapmhcaljjkde
GNU General Public License v2.0
312 stars 52 forks source link

How to make it working with Readmoo reader #96

Open Alqua opened 1 year ago

Alqua commented 1 year ago

Hello, I am using the browser version of Readmoo reader to read ebooks. The popup dictionary work on one page but doesn't work on the next. When it doesn't work, I can see the hovering selecting the right combination of characters but no popup definition is appearing. I also do not understand why it is working on only one page and not on the other. Any idea on how to solve this problem?

chinese-words-separator commented 1 year ago

Hello, I am using the browser version of Readmoo reader to read ebooks. The popup dictionary work on one page but doesn't work on the next. When it doesn't work, I can see the hovering selecting the right combination of characters but no popup definition is appearing. I also do not understand why it is working on only one page and not on the other. Any idea on how to solve this problem?

What's the link where hovering highlights the combination of characters? I can't even get the highlighting work on any books I selected from the main page https://readmoo.com/

Alqua commented 1 year ago

It is with the readmoo reader. You can try with free ebook from here: https://readmoo.com/block/drm_free It looks like this then: 2NLy4BWpYo

You might have to deactivate and reactivate zhongwen to get the highlighting, I also manage to get it to work like that twice but it's not reliable.

Alqua commented 1 year ago

I don't understand what prevent it to work like on other pages.

Alqua commented 1 year ago

oh, also, I'm using firefox.

chinese-words-separator commented 1 year ago

oh, also, I'm using firefox.

Ah it is totally not working on Chrome

https://new-read.readmoo.com/mooreader/210005932000101/preview

Readmoo's main text is XML-based, and Zhongwen inserts HTML text directly, hence this error:

image

Zhongwen's error is in line 698:

image

If the document is XML-based (just as in the case of readmoo), you cannot coerce jQuery's .html method to insert text-based HTML to the document, nor you can use the browser's built-in .innerHTML property

To work around on that, each HTML must be created via object (i.e. via document.createElement), see code from line 702 to 706:

image

See the Zhongwen's code modification below (Hello great World), it works. Notice that another dictionary can work on XML-based document, the Chinese dictionary extension is Inkah, it is available on Firefox. Presumably, Inkah's code uses document.createElement too. Inkah's on/off also need to be re-toggled to for it to work on readmoo

image

Chinese words separator is not yet available on Firefox. If CWS is ported to Firefox, presumably it will work on Firefox too, as CWS is not inserting HTML text to the page directly, it uses document.createElement too.

For what it's worth, CWS can be made to work on readmoo on Chrome, but the users need to do some digging (press F12, then inspect the element) by themselves, see screenshot below how to obtain readmoo's XML's direct link:

image

For https://new-read.readmoo.com/mooreader/210005932000101/preview, its XML direct link is https://reader.readmoo.com/book/preview/210005932000101/OEBPS/Text/Foreword01.xhtml

Here's an example dictionary output of CWS on Chrome on readmoo's direct XML link:

image

Zhongwen's code showPopup code need a little revamping for it to work with XML-based document:

image
chinese-words-separator commented 1 year ago

Made Chinese words separator able to work on Readmoo's site. No more need for users to dig for Readmoo's XML direct link

CWS's tag-less mode:

image

CWS's beginner mode:

image
Alqua commented 1 year ago

Made Chinese words separator able to work on Readmoo's site. No more need for users to dig for Readmoo's XML direct link

CWS's tag-less mode:

image

CWS's beginner mode:

image

Hey, This is awesome. I didn't know cws. It seems like you enable a lot of possibilities with this project. I'd be curious to try netflix subs someday and also would enjoy a firefox version. I do not mind to change to chrome for now though. However, I still have a question. How do you activate the tagless mode? like just popup dictionary and normal text? I could not find it in the options so far.

chinese-words-separator commented 1 year ago

Made wrong analysis, it's not that only by using object can make things work per se, things will also work by replacing the unrecognized XML tags, e.g., &nbsp; and <br> are invalid XML tags. &nbsp; should be replaced with space `,
should be replaced with
`

Zhongwen can now be made to work on Readmoo using the mentioned fixes

image

The fix is trivial:

image
chinese-words-separator commented 1 year ago

Hey, This is awesome. I didn't know cws. It seems like you enable a lot of possibilities with this project. I'd be curious to try netflix subs someday and also would enjoy a firefox version. I do not mind to change to chrome for now though. However, I still have a question. How do you activate the tagless mode? like just popup dictionary and normal text? I could not find it in the options so far.

Use right click on CWS's toolbar icon, then select tag-less word dictionary from this menu:

image

By the way, Chinese words separator version 8.24.84.960 will work on Readmoo, it's published just now on Chrome web store. If by any chance you get the older version 8.24.84.950, just wait for your Chrome to automatically update all the extensions; or to manually update, click the Update button in Chrome's extension settings

chinese-words-separator commented 1 year ago

Fix for Zhongwen's showPopup code:

// https://stackoverflow.com/questions/9625602/how-to-display-nbsp-in-xml-output
html = html
    .replaceAll('&nbsp;', '&#160;')
    .replaceAll('<br>', '<br/>');

$(popup).html(html);