diff --git a/readability/__init__.py b/readability/__init__.py index da3c4e9..58abb23 100644 --- a/readability/__init__.py +++ b/readability/__init__.py @@ -27,6 +27,11 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): view = None buttons = None + style = "" + scriptReadability = "" + scriptToolbar = "" + scriptCall = "" + def init(self, state, settingsPath): self.config = { "settingsFile": os.path.join(settingsPath, "readability", "settings.ini"), @@ -86,10 +91,7 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): self.makeReadability ) - def makeReadability(self, view=None): - if view: - self.view = view - + def loadStyle(self): dataDir = os.path.join(os.path.dirname(__file__), "data") iconClose = Falkon.QzTools.pixmapToDataUrl( @@ -125,20 +127,33 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): css = css.replace("{iconArrow}", iconArrow) css = css.replace("{iconControls}", iconControls) - javascript = Falkon.QzTools.readAllFileContents( - os.path.join(dataDir, "Readability.js") - ) - toolbar = Falkon.QzTools.readAllFileContents( - os.path.join(dataDir, "Toolbar.js") - ) - call = Falkon.QzTools.readAllFileContents( - os.path.join(dataDir, "Call.js") - ) - call = call.replace("{readability.js}", javascript) - call = call.replace("{toolbar.js}", toolbar) - call = call.replace("{style.css}", css) + return css - self.view.page().runJavaScript(call) + def makeReadability(self, view=None): + if view: + self.view = view + + dataDir = os.path.join(os.path.dirname(__file__), "data") + + if not self.style: + self.style = self.loadStyle() + if not self.scriptReadability: + self.scriptReadability = Falkon.QzTools.readAllFileContents( + os.path.join(dataDir, "Readability.js") + ) + if not self.scriptToolbar: + self.scriptToolbar = Falkon.QzTools.readAllFileContents( + os.path.join(dataDir, "Toolbar.js") + ) + if not self.scriptCall: + self.scriptCall = Falkon.QzTools.readAllFileContents( + os.path.join(dataDir, "Call.js") + ) + self.scriptCall = self.scriptCall.replace("{readability.js}", self.scriptReadability) + self.scriptCall = self.scriptCall.replace("{toolbar.js}", self.scriptToolbar) + self.scriptCall = self.scriptCall.replace("{style.css}", self.style) + + self.view.page().runJavaScript(self.scriptCall) def showSettings(self, parent): settings = SettingsDialog(self.config, parent)