diff --git a/readability/__init__.py b/readability/__init__.py index 58abb23..a95af43 100644 --- a/readability/__init__.py +++ b/readability/__init__.py @@ -36,7 +36,10 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): self.config = { "settingsFile": os.path.join(settingsPath, "readability", "settings.ini"), "icon": "dark", - "contextMenu": False + "contextMenu": False, + "colorTheme": "sepia", + "font": "sans-serif", + "fontSize": 5 } self.buttons = {} self.loadSettings() @@ -153,7 +156,16 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): self.scriptCall = self.scriptCall.replace("{toolbar.js}", self.scriptToolbar) self.scriptCall = self.scriptCall.replace("{style.css}", self.style) - self.view.page().runJavaScript(self.scriptCall) + initConfigScript = "initConfig('{}', '{}', {});".format( + self.config["colorTheme"], + self.config["font"], + self.config["fontSize"] + ) + + self.view.page().runJavaScript( + self.scriptCall + initConfigScript, + Falkon.WebPage.SafeJsWorld + ) def showSettings(self, parent): settings = SettingsDialog(self.config, parent) @@ -167,6 +179,9 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): settings.beginGroup("Readability") settings.setValue("icon", self.config["icon"]) settings.setValue("showInContextMenu", self.config["contextMenu"]) + settings.setValue("colorTheme", self.config["colorTheme"]) + settings.setValue("font", self.config["font"]) + settings.setValue("fontSize", self.config["fontSize"]) settings.endGroup() settings.sync() @@ -179,6 +194,9 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): self.config["contextMenu"] = str2bool( settings.value("showInContextMenu", self.config["contextMenu"]) ) + self.config["colorTheme"] = str(settings.value("colorTheme", self.config["colorTheme"])) + self.config["font"] = str(settings.value("font", self.config["font"])) + self.config["fontSize"] = int(settings.value("fontSize", self.config["fontSize"])) settings.endGroup() def onConfigUpdate(self): diff --git a/readability/data/Call.js b/readability/data/Call.js index 8ca5ad7..4c424ba 100644 --- a/readability/data/Call.js +++ b/readability/data/Call.js @@ -108,4 +108,28 @@ function renderPage(article){ } } -callReadability(); \ No newline at end of file +function initConfig(colorTheme, font, fontSize){ + switch(colorTheme) { + case "light": + switchToLight(); + break; + case "dark": + switchToDark(); + break; + case "sepia": + default: + switchToSepia(); + } + switch(font){ + case "serif": + switchToSerif(); + break; + case "sans-serif": + default: + switchToSansSerif(); + } + + fontSizeSet(fontSize); +} + +callReadability(); diff --git a/readability/data/Toolbar.js b/readability/data/Toolbar.js index f56810b..cfd396b 100644 --- a/readability/data/Toolbar.js +++ b/readability/data/Toolbar.js @@ -143,3 +143,17 @@ function fontSizeMinus(){ } } } + +function fontSizeSet(fontSize){ + if (fontSize < 1 || fontSize > 9) + return + + var container = document.getElementById('container'); + for (var i = 0; i < container.classList.length; i++){ + if(container.classList[i].indexOf('font-size') > -1){ + container.classList.remove(container.classList[i]); + container.classList.add('font-size' + fontSize); + return; + } + } +}