Split script loading and preparing routine
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
54d12f8d2b
commit
4a404898ca
@ -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(
|
||||
return css
|
||||
|
||||
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")
|
||||
)
|
||||
toolbar = Falkon.QzTools.readAllFileContents(
|
||||
if not self.scriptToolbar:
|
||||
self.scriptToolbar = Falkon.QzTools.readAllFileContents(
|
||||
os.path.join(dataDir, "Toolbar.js")
|
||||
)
|
||||
call = Falkon.QzTools.readAllFileContents(
|
||||
if not self.scriptCall:
|
||||
self.scriptCall = 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.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(call)
|
||||
self.view.page().runJavaScript(self.scriptCall)
|
||||
|
||||
def showSettings(self, parent):
|
||||
settings = SettingsDialog(self.config, parent)
|
||||
|
Loading…
Reference in New Issue
Block a user