mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
css_tweaks: add generic setting for smaller inpage footnotes (#13613)
Replaces the 3 '... (smaller)' tweaks.
This commit is contained in:
committed by
GitHub
parent
521401c113
commit
cfc67797e2
@@ -24,8 +24,9 @@ local T = require("ffi/util").template
|
||||
-- Default globally enabled style tweaks, for new installations
|
||||
local DEFAULT_GLOBAL_STYLE_TWEAKS = {}
|
||||
-- Display in-page per-specs footnotes for EPUB and FB2:
|
||||
DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_epub_smaller"] = true
|
||||
DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_epub"] = true
|
||||
DEFAULT_GLOBAL_STYLE_TWEAKS["footnote-inpage_fb2"] = true
|
||||
DEFAULT_GLOBAL_STYLE_TWEAKS["inpage_footnote_font-size_smaller"] = true
|
||||
|
||||
local CssTweaks = {
|
||||
DEFAULT_GLOBAL_STYLE_TWEAKS = DEFAULT_GLOBAL_STYLE_TWEAKS,
|
||||
@@ -898,7 +899,7 @@ body[name="comments"] > section
|
||||
{
|
||||
id = "footnote-inpage_epub",
|
||||
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
|
||||
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_epub") end,
|
||||
global_conflicts_with = false,
|
||||
title = _("In-page EPUB footnotes"),
|
||||
description = _([[
|
||||
Show EPUB footnote text at the bottom of pages that contain links to them.
|
||||
@@ -920,43 +921,10 @@ This only works with footnotes that have specific attributes set by the publishe
|
||||
}
|
||||
]],
|
||||
},
|
||||
{
|
||||
id = "footnote-inpage_epub_smaller",
|
||||
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
|
||||
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_epub") end,
|
||||
title = _("In-page EPUB footnotes (smaller)"),
|
||||
description = _([[
|
||||
Show EPUB footnote text at the bottom of pages that contain links to them.
|
||||
This only works with footnotes that have specific attributes set by the publisher.]]),
|
||||
-- Restrict this to non-FB2 documents, as FB2 can have <a type="note">
|
||||
-- and we don't want to have them smaller
|
||||
css = [[
|
||||
*[type~="note"],
|
||||
*[type~="endnote"],
|
||||
*[type~="footnote"],
|
||||
*[type~="rearnote"],
|
||||
*[role~="doc-note"],
|
||||
*[role~="doc-endnote"],
|
||||
*[role~="doc-footnote"],
|
||||
*[role~="doc-rearnote"]
|
||||
{
|
||||
-cr-only-if: -fb2-document;
|
||||
-cr-hint: footnote-inpage;
|
||||
margin: 0 !important;
|
||||
}
|
||||
/* Also applies to extended footnotes */
|
||||
*, autoBoxing {
|
||||
-cr-hint: late;
|
||||
-cr-only-if: inpage-footnote;
|
||||
font-size: 0.8rem !important;
|
||||
}
|
||||
]],
|
||||
separator = true,
|
||||
},
|
||||
{
|
||||
id = "footnote-inpage_wikipedia",
|
||||
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
|
||||
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_wikipedia") end,
|
||||
global_conflicts_with = false,
|
||||
title = _("In-page Wikipedia footnotes"),
|
||||
description = _([[Show footnotes at the bottom of pages in Wikipedia EPUBs.]]),
|
||||
css = [[
|
||||
@@ -970,37 +938,13 @@ ol.references > li > .noprint { display: none; }
|
||||
ol.references > li > .mw-cite-backlink { display: none; }
|
||||
]],
|
||||
},
|
||||
{
|
||||
id = "footnote-inpage_wikipedia_smaller",
|
||||
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
|
||||
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_wikipedia") end,
|
||||
title = _("In-page Wikipedia footnotes (smaller)"),
|
||||
description = _([[Show footnotes at the bottom of pages in Wikipedia EPUBs.]]),
|
||||
css = [[
|
||||
ol.references > li {
|
||||
-cr-hint: footnote-inpage;
|
||||
list-style-position: -cr-outside;
|
||||
margin: 0 !important;
|
||||
}
|
||||
/* Also applies to extended footnotes */
|
||||
*, autoBoxing {
|
||||
-cr-hint: late;
|
||||
-cr-only-if: inpage-footnote;
|
||||
font-size: 0.8rem !important;
|
||||
}
|
||||
/* hide backlinks */
|
||||
ol.references > li > .noprint { display: none; }
|
||||
ol.references > li > .mw-cite-backlink { display: none; }
|
||||
]],
|
||||
separator = true,
|
||||
},
|
||||
-- We can add other classic classnames to the 2 following
|
||||
-- tweaks (except when named 'calibreN', as the N number is
|
||||
-- We can add other classic classnames to the following
|
||||
-- tweak (except when named 'calibreN', as the N number is
|
||||
-- usually random across books).
|
||||
{
|
||||
id = "footnote-inpage_classic_classnames",
|
||||
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
|
||||
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_classic_classnames") end,
|
||||
global_conflicts_with = false,
|
||||
title = _("In-page classic classname footnotes"),
|
||||
description = _([[
|
||||
Show footnotes with classic classnames at the bottom of pages.
|
||||
@@ -1016,32 +960,6 @@ This tweak can be duplicated as a user style tweak when books contain footnotes
|
||||
{
|
||||
-cr-hint: footnote-inpage;
|
||||
margin: 0 !important;
|
||||
}
|
||||
]],
|
||||
},
|
||||
{
|
||||
id = "footnote-inpage_classic_classnames_smaller",
|
||||
conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_") end,
|
||||
global_conflicts_with = function(id) return util.stringStartsWith(id, "footnote-inpage_classic_classnames") end,
|
||||
title = _("In-page classic classname footnotes (smaller)"),
|
||||
description = _([[
|
||||
Show footnotes with classic classnames at the bottom of pages.
|
||||
This tweak can be duplicated as a user style tweak when books contain footnotes wrapped with other class names.]]),
|
||||
css = [[
|
||||
.footnote, .footnotes, .fn,
|
||||
.note, .note1, .note2, .note3,
|
||||
.ntb, .ntb-txt, .ntb-txt-j,
|
||||
.przypis, .przypis1, /* Polish footnotes */
|
||||
.voetnoten /* Dutch footnotes */
|
||||
{
|
||||
-cr-hint: footnote-inpage;
|
||||
margin: 0 !important;
|
||||
}
|
||||
/* Also applies to extended footnotes */
|
||||
*, autoBoxing {
|
||||
-cr-hint: late;
|
||||
-cr-only-if: inpage-footnote;
|
||||
font-size: 0.8rem !important;
|
||||
}
|
||||
]],
|
||||
separator = true,
|
||||
@@ -1102,6 +1020,21 @@ This tweak can be duplicated as a user style tweak when a book contains other el
|
||||
(function()
|
||||
local sub_table = {
|
||||
title = _("In-page footnote font size"),
|
||||
{
|
||||
id = "inpage_footnote_font-size_smaller",
|
||||
conflicts_with = function(id) return util.stringStartsWith(id, "inpage_footnote_font-size_") end,
|
||||
title = _("Smaller footnotes (80%, legacy)"),
|
||||
description = _([[
|
||||
Decrease size of in-page footnotes. This may have no effect if it's overwritten by publisher styles. The "footnote font size" style tweaks are recommended instead.]]),
|
||||
css = [[
|
||||
*, autoBoxing {
|
||||
-cr-hint: late;
|
||||
-cr-only-if: -fb2-document inpage-footnote;
|
||||
font-size: 0.8rem !important;
|
||||
}
|
||||
]],
|
||||
separator = true,
|
||||
},
|
||||
}
|
||||
for __, rem in ipairs( { 1.0, 0.9, 0.85, 0.8, 0.75, 0.7, 0.65 } ) do
|
||||
local pct = rem * 100
|
||||
|
||||
@@ -12,7 +12,7 @@ local util = require("util")
|
||||
local _ = require("gettext")
|
||||
|
||||
-- Date at which the last migration snippet was added
|
||||
local CURRENT_MIGRATION_DATE = 20250405
|
||||
local CURRENT_MIGRATION_DATE = 20250601
|
||||
|
||||
-- Retrieve the date of the previous migration, if any
|
||||
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
|
||||
@@ -34,15 +34,6 @@ local function drop_fontcache()
|
||||
end
|
||||
end
|
||||
|
||||
-- Global settings, https://github.com/koreader/koreader/pull/4945 & https://github.com/koreader/koreader/pull/5655
|
||||
-- Limit the check to the most recent update. ReaderUI calls this one unconditionally to update docsettings, too.
|
||||
if last_migration_date < 20191129 then
|
||||
logger.info("Performing one-time migration for 20191129")
|
||||
|
||||
local SettingsMigration = require("ui/data/settings_migration")
|
||||
SettingsMigration:migrateSettings(G_reader_settings)
|
||||
end
|
||||
|
||||
-- ReaderTypography, https://github.com/koreader/koreader/pull/6072
|
||||
if last_migration_date < 20200421 then
|
||||
logger.info("Performing one-time migration for 20200421")
|
||||
@@ -886,5 +877,17 @@ if last_migration_date < 20250405 then
|
||||
G_reader_settings:delSetting("show_finished")
|
||||
end
|
||||
|
||||
-- Global settings, https://github.com/koreader/koreader/pull/4945 & https://github.com/koreader/koreader/pull/5655
|
||||
-- Limit the check to the most recent update. ReaderUI calls this one unconditionally to update docsettings, too.
|
||||
-- 20250601, Refactor default footnote style tweaks
|
||||
-- https://github.com/koreader/koreader/pull/13613
|
||||
if last_migration_date < 20250601 then
|
||||
logger.info("Performing one-time migration for 20250601")
|
||||
|
||||
local SettingsMigration = require("ui/data/settings_migration")
|
||||
SettingsMigration:migrateSettings(G_reader_settings)
|
||||
end
|
||||
|
||||
|
||||
-- We're done, store the current migration date
|
||||
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)
|
||||
|
||||
@@ -45,6 +45,62 @@ function SettingsMigration:migrateSettings(config)
|
||||
config:saveSetting("copt_word_spacing", { 100, space_condensing })
|
||||
end
|
||||
|
||||
if config:has("style_tweaks") then
|
||||
local tweaks = config:readSetting("style_tweaks")
|
||||
if tweaks then
|
||||
-- try to preserve user intent when flattening the previous combination of
|
||||
-- ["footnote-inpage_x", "footnote-inpage_x_smaller"] into ["footnote-inpage_x"]
|
||||
--
|
||||
-- | x_smaller |
|
||||
-- | nil | true | false |
|
||||
-- -----------+-------+-------+-------+
|
||||
-- nil | nil | true | false |
|
||||
-- x true | true | true | true |
|
||||
-- false | false | true | false |
|
||||
-- -----------+-----------------------+
|
||||
--
|
||||
-- If either tweak is true, enable the base tweak to keep that type of footnote.
|
||||
-- (Preserving small vs normal size is handled below)
|
||||
-- If one was false and the other nil or also false, we had a default
|
||||
-- that was disabled for the current book and want to keep it false.
|
||||
-- If both are nil they were both disabled (global settings) or both using their
|
||||
-- respective default values (book settings) and we keep it as nil
|
||||
|
||||
if tweaks["footnote-inpage_epub"] or tweaks["footnote-inpage_epub_smaller"] then
|
||||
tweaks["footnote-inpage_epub"] = true
|
||||
elseif tweaks["footnote-inpage_epub"] == false or tweaks["footnote-inpage_epub_smaller"] == false then
|
||||
tweaks["footnote-inpage_epub"] = false
|
||||
end
|
||||
if tweaks["footnote-inpage_wikipedia"] or tweaks["footnote-inpage_wikipedia_smaller"] then
|
||||
tweaks["footnote-inpage_wikipedia"] = true
|
||||
elseif tweaks["footnote-inpage_wikipedia"] == false or tweaks["footnote-inpage_wikipedia_smaller"] == false then
|
||||
tweaks["footnote-inpage_wikipedia"] = false
|
||||
end
|
||||
if tweaks["footnote-inpage_classic_classnames"] or tweaks["footnote-inpage_classic_classnames_smaller"] then
|
||||
tweaks["footnote-inpage_classic_classnames"] = true
|
||||
elseif tweaks["footnote-inpage_classic_classnames"] == false or tweaks["footnote-inpage_classic_classnames_smaller"] == false then
|
||||
tweaks["footnote-inpage_classic_classnames"] = false
|
||||
end
|
||||
|
||||
local forced_size = false
|
||||
for __, pct in ipairs( { 100, 90, 85, 80, 75, 70, 65 } ) do
|
||||
if tweaks["inpage_footnote_font-size_" .. pct] then
|
||||
forced_size = true
|
||||
end
|
||||
end
|
||||
if not forced_size
|
||||
and (tweaks["footnote-inpage_epub_smaller"]
|
||||
or tweaks["footnote-inpage_wikipedia_smaller"]
|
||||
or tweaks["footnote-inpage_classic_classnames_smaller"]
|
||||
) then
|
||||
tweaks["inpage_footnote_font-size_smaller"] = true
|
||||
end
|
||||
|
||||
tweaks["footnote-inpage_epub_smaller"] = nil
|
||||
tweaks["footnote-inpage_wikipedia_smaller"] = nil
|
||||
tweaks["footnote-inpage_classic_classnames_smaller"] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return SettingsMigration
|
||||
|
||||
Reference in New Issue
Block a user