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
|
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
|
||||||
|
|
||||||
|
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")
|
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")
|
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")
|
os.path.join(dataDir, "Call.js")
|
||||||
)
|
)
|
||||||
call = call.replace("{readability.js}", javascript)
|
self.scriptCall = self.scriptCall.replace("{readability.js}", self.scriptReadability)
|
||||||
call = call.replace("{toolbar.js}", toolbar)
|
self.scriptCall = self.scriptCall.replace("{toolbar.js}", self.scriptToolbar)
|
||||||
call = call.replace("{style.css}", css)
|
self.scriptCall = self.scriptCall.replace("{style.css}", self.style)
|
||||||
|
|
||||||
self.view.page().runJavaScript(call)
|
self.view.page().runJavaScript(self.scriptCall)
|
||||||
|
|
||||||
def showSettings(self, parent):
|
def showSettings(self, parent):
|
||||||
settings = SettingsDialog(self.config, parent)
|
settings = SettingsDialog(self.config, parent)
|
||||||
|
Loading…
Reference in New Issue
Block a user