Last active
May 20, 2017 22:46
-
-
Save fchasen/6f028c107f82566c349d to your computer and use it in GitHub Desktop.
Get the current shown text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Book.on("renderer:visibleRangeChanged", function(cfirange) { | |
var text = ''; | |
var cfi = new EPUBJS.EpubCFI(); | |
var startRange = cfi.generateRangeFromCfi(cfirange.start, Book.renderer.render.document); | |
var endRange = cfi.generateRangeFromCfi(cfirange.end, Book.renderer.render.document); | |
// Create a new range to handle full cfi range (this should be fixed in v0.3) | |
var fullRange = document.createRange(); | |
if (startRange) { | |
fullRange.setStart(startRange.startContainer, startRange.startOffset); | |
} | |
if (endRange) { | |
fullRange.setEnd(endRange.startContainer, endRange.startOffset); | |
} | |
text = fullRange.toString(); | |
console.log(text); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello Fchasen,
I know that the example here shows how to select everything on the page.
what I want is to be able to programmatically select a portion of the visible page.
pls help.