diff options
Diffstat (limited to 'js/reader.js')
-rw-r--r-- | js/reader.js | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/js/reader.js b/js/reader.js index aeae46c..d1868ac 100644 --- a/js/reader.js +++ b/js/reader.js @@ -520,7 +520,7 @@ const Reader = { `); $(".font_family").val(await localforage.getItem("epube.fontFamily") || DEFAULT_FONT_FAMILY); - $(".theme_name").val(await localforage.getItem("epube.theme")); + $(".theme_name").val(await localforage.getItem("epube.theme") || 'default'); const zoom = $(".font_size").html(""); @@ -1007,49 +1007,45 @@ const Reader = { }); }, - applyTheme: function() { - localforage.getItem("epube.theme").then(function(theme) { - if (!theme) theme = 'default'; + applyTheme: async function() { + let theme = await localforage.getItem("epube.theme") || "default"; - console.log('called for theme', theme); + console.log('called for theme', theme); - if (theme == "default" && typeof EpubeApp != "undefined") - if (EpubeApp.isNightMode()) - theme = "night"; + if (theme == "default" && typeof EpubeApp != "undefined") + if (EpubeApp.isNightMode()) + theme = "night"; - console.log('setting main UI theme', theme); + console.log('setting main UI theme', theme); - $("body") - .attr("class", typeof EpubeApp != "undefined" ? "is-epube-app" : "") - .addClass("epube-reader theme-" + theme) - .attr("data-is-loading", "false"); - - if (typeof EpubeApp != "undefined") { - - window.setTimeout(function() { - const bg_color = window.getComputedStyle(document.querySelector("body"), null) - .getPropertyValue("background-color"); + $("body") + .attr("class", typeof EpubeApp != "undefined" ? "is-epube-app" : "") + .addClass("epube-reader theme-" + theme) + .attr("data-is-loading", "false"); - const match = bg_color.match(/rgb\((\d{1,}), (\d{1,}), (\d{1,})\)/); + if (typeof EpubeApp != "undefined") { + window.setTimeout(function() { + const bg_color = window.getComputedStyle(document.querySelector("body"), null) + .getPropertyValue("background-color"); - if (match) { - console.log("sending bgcolor", match); + const match = bg_color.match(/rgb\((\d{1,}), (\d{1,}), (\d{1,})\)/); - EpubeApp.setStatusBarColor(parseInt(match[1]), parseInt(match[2]), parseInt(match[3])); - } - }, 250); - } + if (match) { + console.log("sending bgcolor", match); - if (window.book) - $.each(window.book.rendition.getContents(), function(i, c) { - console.log('applying rendition theme', theme, 'to', c, c.document); + EpubeApp.setStatusBarColor(parseInt(match[1]), parseInt(match[2]), parseInt(match[3])); + } + }, 250); + } - $(c.document).find("body") - .attr("class", typeof EpubeApp != "undefined" ? "is-epube-app" : "") - .addClass("theme-" + theme); - }); + if (window.book) + $.each(window.book.rendition.getContents(), function(i, c) { + console.log('applying rendition theme', theme, 'to', c, c.document); - }); + $(c.document).find("body") + .attr("class", typeof EpubeApp != "undefined" ? "is-epube-app" : "") + .addClass("theme-" + theme); + }); }, hotkeyHandler: function(e) { try { |