gerhardsletten / react-reader

An ePub-reader for React, powered by Epub.js
https://react-reader.metabits.no
Apache License 2.0
721 stars 132 forks source link

Add custom options on text selection #160

Closed junior-g closed 1 year ago

junior-g commented 1 year ago

I am developing a note-taking feature where use 1st select the text then a pop-up will appear with a custom box. But now it is opening "copy", "share", "select all", "web search" etc. is there any way I can override these? It is in the Android Mobile view.

junior-g commented 1 year ago

+++

gerhardsletten commented 1 year ago

@junior-g If you google "js disable context menu" you will find a way to disable this. But since epubjs is rendering the epub-file inside an iframe I am not sure if disabling this on the parent document also disable it inside the iframe.

junior-g commented 1 year ago

I tried but didn't worked for me. Also i am using react-reader for Mobile Webview

gerhardsletten commented 1 year ago

@junior-g You just need to dig into epubjs rendition and apply pressure:

<ReactReader
  getRendition={(_rendition: Rendition) => {
    rendition.current = _rendition
    _rendition.hooks.content.register((contents: Contents) => {
      const body = contents.window.document.querySelector('body')
      if (body) {
        body.oncontextmenu = () => {
          return false
        }
      }
    })
  }}
/>