2019-06-10 22:24:42 +02:00
|
|
|
import Falkon
|
2019-06-11 00:08:05 +02:00
|
|
|
import os
|
|
|
|
from PySide2 import QtCore, QtGui
|
2019-06-10 22:24:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Readability(Falkon.PluginInterface, QtCore.QObject):
|
2019-06-11 00:08:05 +02:00
|
|
|
view = None
|
|
|
|
|
2019-06-10 22:24:42 +02:00
|
|
|
def init(self, state, settingsPath):
|
|
|
|
plugins = Falkon.MainApplication.instance().plugins()
|
|
|
|
|
|
|
|
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
2019-06-11 00:08:05 +02:00
|
|
|
plugins.mainWindowDeleted.connect(self.onMainWindowDeleted)
|
2019-06-10 22:24:42 +02:00
|
|
|
|
|
|
|
if state == Falkon.PluginInterface.LateInitState:
|
|
|
|
for window in Falkon.MainApplication.instance().windows():
|
|
|
|
self.onMainWindowCreated(window)
|
|
|
|
|
|
|
|
def unload(self):
|
|
|
|
for window in Falkon.MainApplication.instance().windows():
|
2019-06-11 00:08:05 +02:00
|
|
|
self.onMainWindowDeleted(window)
|
2019-06-10 22:24:42 +02:00
|
|
|
|
|
|
|
def testPlugin(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def onMainWindowCreated(self, window):
|
|
|
|
pass
|
|
|
|
|
2019-06-11 00:08:05 +02:00
|
|
|
def onMainWindowDeleted(self, window):
|
2019-06-10 22:24:42 +02:00
|
|
|
pass
|
|
|
|
|
2019-06-11 00:08:05 +02:00
|
|
|
def populateWebViewMenu(self, menu, view, hitTestResult):
|
|
|
|
self.view = view
|
|
|
|
|
|
|
|
if (hitTestResult.imageUrl().isEmpty()
|
|
|
|
and hitTestResult.linkUrl().isEmpty()
|
|
|
|
and hitTestResult.mediaUrl().isEmpty()
|
|
|
|
and not hitTestResult.isContentEditable()
|
|
|
|
and not hitTestResult.isContentSelected()):
|
|
|
|
menu.addAction(
|
|
|
|
QtGui.QIcon(os.path.join(os.path.dirname(__file__), "data", "icon.png")),
|
|
|
|
"Readability",
|
|
|
|
self.makeReadability
|
|
|
|
)
|
|
|
|
|
|
|
|
def makeReadability(self):
|
|
|
|
dataDir = os.path.join(os.path.dirname(__file__), "data")
|
|
|
|
|
|
|
|
iconClose = Falkon.QzTools.pixmapToDataUrl(
|
|
|
|
QtGui.QPixmap(os.path.join(dataDir, "RM-close.png"))
|
|
|
|
).toString()
|
|
|
|
iconCloseHover = Falkon.QzTools.pixmapToDataUrl(
|
|
|
|
QtGui.QPixmap(os.path.join(dataDir, "RM-close-hover.png"))
|
|
|
|
).toString()
|
|
|
|
iconDelete = Falkon.QzTools.pixmapToDataUrl(
|
|
|
|
QtGui.QPixmap(os.path.join(dataDir, "RM-Delete-24x24.png"))
|
|
|
|
).toString()
|
|
|
|
iconPlus = Falkon.QzTools.pixmapToDataUrl(
|
|
|
|
QtGui.QPixmap(os.path.join(dataDir, "RM-Plus-24x24.png"))
|
|
|
|
).toString()
|
|
|
|
iconMinus = Falkon.QzTools.pixmapToDataUrl(
|
|
|
|
QtGui.QPixmap(os.path.join(dataDir, "RM-Minus-24x24.png"))
|
|
|
|
).toString()
|
|
|
|
iconArrow = Falkon.QzTools.readAllFileContents(
|
|
|
|
os.path.join(dataDir, "RM-Type-Controls-Arrow.png")
|
|
|
|
)
|
|
|
|
iconControls = Falkon.QzTools.pixmapToDataUrl(
|
|
|
|
QtGui.QPixmap(os.path.join(dataDir, "RM-Type-Controls-24x24.png"))
|
|
|
|
).toString()
|
|
|
|
|
|
|
|
css = Falkon.QzTools.readAllFileContents(
|
|
|
|
os.path.join(dataDir, "style.css")
|
|
|
|
).replace("\n", "")
|
|
|
|
css = css.replace("{1}", iconClose)
|
|
|
|
css = css.replace("{2}", iconCloseHover)
|
|
|
|
css = css.replace("{3}", iconDelete)
|
|
|
|
css = css.replace("{4}", iconPlus)
|
|
|
|
css = css.replace("{5}", iconMinus)
|
|
|
|
css = css.replace("{6}", iconArrow)
|
|
|
|
css = css.replace("{7}", 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("{1}", javascript)
|
|
|
|
call = call.replace("{2}", toolbar)
|
|
|
|
call = call.replace("{3}", css)
|
|
|
|
|
|
|
|
self.view.page().runJavaScript(call)
|
|
|
|
|
2019-06-10 22:24:42 +02:00
|
|
|
|
|
|
|
Falkon.registerPlugin(Readability())
|