Greasemonkey: ensure only GM scripts are cleaned up on reload.

WebEngine only. Previously we were just removing every script from the
main world. But some other scripts might got here in the future so new
we are overriding the name field to add a GM- prefix so hopefully we
only remove greasemonkey scripts before adding new ones.
This commit is contained in:
Jimmy 2017-10-04 23:25:22 +13:00
parent fd5d44182b
commit a7f41b4564

View File

@ -263,7 +263,9 @@ def inject_userscripts():
for profile in [default_profile, private_profile]:
scripts = profile.scripts()
for script in scripts.toList():
if script.worldId() == QWebEngineScript.MainWorld:
if script.name().startswith("GM-"):
log.greasemonkey.debug('removing script: {}'
.format(script.name()))
scripts.remove(script)
for profile in [default_profile, private_profile]:
@ -273,6 +275,7 @@ def inject_userscripts():
new_script = QWebEngineScript()
new_script.setWorldId(QWebEngineScript.MainWorld)
new_script.setSourceCode(script.code())
new_script.setName("GM-{}".format(script.name))
log.greasemonkey.debug('adding script: %s', new_script.name())
scripts.insert(new_script)