Split script loading and preparing routine

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-20 18:51:14 +02:00
parent 54d12f8d2b
commit 4a404898ca
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07

View File

@ -27,6 +27,11 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
view = None view = None
buttons = None buttons = None
style = ""
scriptReadability = ""
scriptToolbar = ""
scriptCall = ""
def init(self, state, settingsPath): def init(self, state, settingsPath):
self.config = { self.config = {
"settingsFile": os.path.join(settingsPath, "readability", "settings.ini"), "settingsFile": os.path.join(settingsPath, "readability", "settings.ini"),
@ -86,10 +91,7 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
self.makeReadability self.makeReadability
) )
def makeReadability(self, view=None): def loadStyle(self):
if view:
self.view = view
dataDir = os.path.join(os.path.dirname(__file__), "data") dataDir = os.path.join(os.path.dirname(__file__), "data")
iconClose = Falkon.QzTools.pixmapToDataUrl( iconClose = Falkon.QzTools.pixmapToDataUrl(
@ -125,20 +127,33 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
css = css.replace("{iconArrow}", iconArrow) css = css.replace("{iconArrow}", iconArrow)
css = css.replace("{iconControls}", iconControls) css = css.replace("{iconControls}", iconControls)
javascript = Falkon.QzTools.readAllFileContents( return css
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)
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): def showSettings(self, parent):
settings = SettingsDialog(self.config, parent) settings = SettingsDialog(self.config, parent)