Only get greasemonkey object once

This commit is contained in:
Florian Bruhin 2018-06-26 10:39:04 +02:00
parent 61da5d0c7c
commit 1536843f33

View File

@ -788,6 +788,7 @@ class _WebEngineScripts(QObject):
super().__init__(parent) super().__init__(parent)
self._tab = tab self._tab = tab
self._widget = None self._widget = None
self._greasemonkey = objreg.get('greasemonkey')
def connect_signals(self): def connect_signals(self):
config.instance.changed.connect(self._on_config_changed) config.instance.changed.connect(self._on_config_changed)
@ -860,8 +861,7 @@ class _WebEngineScripts(QObject):
self._widget.page().urlChanged.connect( self._widget.page().urlChanged.connect(
self._inject_greasemonkey_scripts_for_url) self._inject_greasemonkey_scripts_for_url)
else: else:
greasemonkey = objreg.get('greasemonkey') self._greasemonkey.scripts_reloaded.connect(
greasemonkey.scripts_reloaded.connect(
self._inject_all_greasemonkey_scripts) self._inject_all_greasemonkey_scripts)
self._inject_all_greasemonkey_scripts() self._inject_all_greasemonkey_scripts()
@ -881,8 +881,7 @@ class _WebEngineScripts(QObject):
self._inject_early_js('stylesheet', js_code, subframes=True) self._inject_early_js('stylesheet', js_code, subframes=True)
def _inject_greasemonkey_scripts_for_url(self, url): def _inject_greasemonkey_scripts_for_url(self, url):
greasemonkey = objreg.get('greasemonkey') matching_scripts = self._greasemonkey.scripts_for(url)
matching_scripts = greasemonkey.scripts_for(url)
self._inject_greasemonkey_scripts( self._inject_greasemonkey_scripts(
matching_scripts.start, QWebEngineScript.DocumentCreation, True) matching_scripts.start, QWebEngineScript.DocumentCreation, True)
self._inject_greasemonkey_scripts( self._inject_greasemonkey_scripts(
@ -891,8 +890,7 @@ class _WebEngineScripts(QObject):
matching_scripts.idle, QWebEngineScript.Deferred, False) matching_scripts.idle, QWebEngineScript.Deferred, False)
def _inject_all_greasemonkey_scripts(self): def _inject_all_greasemonkey_scripts(self):
greasemonkey = objreg.get('greasemonkey') scripts = self._greasemonkey.all_scripts()
scripts = greasemonkey.all_scripts()
self._inject_greasemonkey_scripts(scripts) self._inject_greasemonkey_scripts(scripts)
def _inject_greasemonkey_scripts(self, scripts=None, injection_point=None, def _inject_greasemonkey_scripts(self, scripts=None, injection_point=None,