-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moby Dick demo doesn't work with Chrome translator extension #571
Comments
the same problem with Lingualeo chrome extension |
The same on google translate Chrome extension, does anyone know how to fix it? 😢 |
Ok, I got a temporary solution here, html: (where the translation appear, put it anywhere you like) <span
id="epubSelection"
style="position: fixed; top: 42vh; right: calc(50vw - 530px); font-size: 0;"
>
</span> typescript: private clientX: number;
private clientY: number;
rendition.once('rendered', () => {
const epubContainer = document.getElementsByClassName('epub-container')[0] as HTMLElement;
const docElement = rendition.getContents()[0].documentElement as HTMLElement;
// Listen to the pointer location in the rendition
docElement.addEventListener('mouseup', event => {
const offsetX = epubContainer.firstElementChild.getBoundingClientRect().left; // epub-view
const offsetY = epubContainer.scrollTop;
this.clientX = event.clientX + offsetX;
this.clientY = event.clientY - offsetY;
});
});
rendition.on('selected', (cfirange, contents) => {
// Copy the selected content from the <iframe> to an outside element
const selection: Selection = contents.window.getSelection();
const element: HTMLElement = document.getElementById('epubSelection');
element.innerText = selection.toString();
// Select the outside element
const range: Range = document.createRange();
range.selectNodeContents(element);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
// Trigger a mouseup event manually
element.dispatchEvent(new MouseEvent('mouseup', {
bubbles: true,
cancelable: true,
clientX: this.clientX,
clientY: this.clientY,
}));
}); Hope this helps. 😃 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I'm using this Chrome extension to translate unknown words while I'm reading: ImTranslator
It works like this:
But when I'm trying it on the demo book "Moby Dick" it doesn't work. When I double click or select text nothing is happening.
Can it be solved somehow? It's essential feature for me.
Thank you.
The text was updated successfully, but these errors were encountered: