Last active
May 26, 2025 15:26
-
-
Save sebdelsol/0722dc3518f7e1c95c7e4851b460849c to your computer and use it in GitHub Desktop.
KOReader userpatch for better compact items status bar
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
-- **MOVED to https://github.com/sebdelsol/KOReader.patches** | |
-- enhance compact items: | |
-- use the better frontlight icons, and add the battery percentage | |
-- better separator for title/chapter/author in compact mode with no separator | |
local ReaderFooter = require("apps/reader/modules/readerfooter") | |
local userpatch = require("userpatch") | |
local footerTextGeneratorMap = userpatch.getUpValue(ReaderFooter.applyFooterMode, "footerTextGeneratorMap") | |
local symbol_prefix = userpatch.getUpValue(footerTextGeneratorMap.frontlight, "symbol_prefix") | |
-- use the better icons for compact items | |
for _, item in ipairs { "frontlight", "frontlight_warmth" } do | |
symbol_prefix.compact_items[item] = symbol_prefix.icons[item] | |
end | |
-- use the battery percent for compact items | |
for _, item in ipairs { "battery" } do | |
local orig = footerTextGeneratorMap[item] | |
footerTextGeneratorMap[item] = function(footer, ...) | |
if footer.settings.item_prefix == "compact_items" then footer.settings.item_prefix = "icons" end | |
local text = orig(footer, ...) | |
footer.settings.item_prefix = "compact_items" -- restore | |
return text | |
end | |
end | |
-- add a separator for title/chapter/author | |
local BEGIN, END = string.char(0x1E), string.char(0x1F) | |
for _, item in ipairs { "book_author", "book_title", "book_chapter" } do | |
local orig = footerTextGeneratorMap[item] | |
footerTextGeneratorMap[item] = function(...) return BEGIN .. orig(...) .. END end | |
end | |
local separator_next = symbol_prefix.compact_items.pages_left | |
local subs = { -- order is important | |
{ pattern = END .. " " .. BEGIN, replace = " " .. separator_next .. " " }, -- sequence of title/chapter/author | |
{ pattern = "^" .. BEGIN, replace = "" }, -- @beginning of string | |
{ pattern = END .. "$", replace = "" }, -- @end of string | |
{ pattern = BEGIN, replace = separator_next .. " " }, --@beginning of title/chapter/author | |
{ pattern = END, replace = "" }, --@end of title/chapter/author | |
} | |
local orig_ReaderFooter_genAllFooterText = ReaderFooter.genAllFooterText | |
function ReaderFooter:genAllFooterText(...) | |
local text, is_filler_inside = orig_ReaderFooter_genAllFooterText(self, ...) | |
if self.settings.item_prefix == "compact_items" and self.settings.items_separator == "none" then | |
-- stylua: ignore | |
for _, sub in ipairs(subs) do text = text:gsub(sub.pattern, sub.replace) end | |
end | |
return text, is_filler_inside | |
end |
It's definitely related and quite specific π (though different from my own idiosyncratic needs):
local ReaderFooter = require("apps/reader/modules/readerfooter")
local userpatch = require("userpatch")
local footerTextGeneratorMap = userpatch.getUpValue(ReaderFooter.applyFooterMode, "footerTextGeneratorMap")
local orig_footerTextGeneratorMap_page_progress = footerTextGeneratorMap.page_progress
footerTextGeneratorMap.page_progress = function(footer)
local text = orig_footerTextGeneratorMap_page_progress(footer)
return "(" .. text:gsub("%s", "\u{200A}") .. ")"
end
footerTextGeneratorMap.chapter_progress = function(footer)
local text = footer:getChapterProgress()
return "(" .. text:gsub("ββ", "/"):gsub("%s", "\u{200A}") .. ")"
end
footerTextGeneratorMap.book_title = function(footer)
local text = footer.ui.doc_props.display_title:sub(1, -7)
return footer:getFittedText(text, footer.settings.book_title_max_width_pct)
end
EDIT : Your last requirement was a little harder than I thought π , please use this edited version
Thanks a lot for these! Appreciate it!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think this is the right place to ask this, but you seem to know your stuff around user patches. So, I want to modify some items in the status bar:
I want to modify the "current page in chapter" to display the value like this:
(2/5)
instead of2//5
I want to modify the "current page" to display the value like this:
(216/534)
instead of216/534
And I want to modify the "book title" value to remove/trim the last 6 characters always
Any help in this is highly appreciated.
BTW this is not related to this user patch at all. I am just asking here because it was related to status bar changes