Skip to content

Commit

Permalink
handle Kindle sample viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
ken107 committed Jan 18, 2024
1 parent 6db16a8 commit ceccf28
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion js/content/kindle-book.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

var readAloudDoc = new function() {
var readAloudDoc = location.pathname.startsWith("/sample/") ? new KindleSample() : new KindleDoc()


function KindleDoc() {
var currentIndex = 0;

this.getCurrentIndex = function() {
Expand All @@ -26,3 +29,23 @@ var readAloudDoc = new function() {
.then(result => result.texts || fixParagraphs(result.lines))
}
}


function KindleSample() {
this.getCurrentIndex = function() {
return 0
}

this.getTexts = function(index) {
return index == 0 ? getTexts() : null
}

function getTexts() {
const elems = $("#kr-renderer").find("div[data-pid]").get()
.filter(el => el.firstChild && el.firstChild.tagName != "DIV")
const index = elems.findIndex(el => el.getBoundingClientRect().top > 100)
return elems.slice(index)
.map(getInnerText)
.filter(text => /[\p{L}\p{Nl}\p{Nd}]/u.test(text))
}
}

0 comments on commit ceccf28

Please sign in to comment.