diff --git a/main.lua b/main.lua index b0fc128..aff42ae 100644 --- a/main.lua +++ b/main.lua @@ -662,6 +662,27 @@ function Bookhoard:getBookhoardUUID() return self.ui.doc_settings:readSetting("bookhoard_uuid") end +function Bookhoard:getContextText() + if not self.ui.document or self.ui.document.info.has_pages then + return "" + end + local xp = self:getLastProgress() + if not xp then return "" end + + local text = self.ui.document:getTextFromXPointer(xp) + if not text or text == "" then + text = self.ui.document:getTextFromXPointer(self.ui.document:getNormalizedXPointer(xp)) + end + if not text or text == "" then return "" end + + if #text > 100 then + text = text:sub(1, 100) + end + + text = text:gsub("%s+", " "):match("^%s*(.-)%s*$") or "" + return text +end + function Bookhoard:collectBookData() local props = self.ui.doc_props local file_path = self.ui.document.file @@ -680,6 +701,7 @@ function Bookhoard:collectBookData() local progress = self:getLastProgress() local page = self.ui:getCurrentPage() local total_pages = self.ui.document:getPageCount() + local context_text = self:getContextText() local book_data = { uuid = book_uuid, @@ -688,6 +710,7 @@ function Bookhoard:collectBookData() authors = authors, percentage = percentage, epubcfi = progress, + context_text = context_text, page = page, total_pages = total_pages, file_path = file_path,