greasemonkey: also support qute-js-world on 5.7.1

A straight copy from webengintab.

Yes I know I shouldn't be importing a private thing from webenginetab,
I'm working on refactoring now.
This commit is contained in:
Jimmy 2018-06-26 13:05:27 +12:00
parent 521268a1f7
commit 324966cfe7

View File

@ -288,7 +288,19 @@ class WebEnginePage(QWebEnginePage):
def _add_script(script, injection_point):
new_script = QWebEngineScript()
new_script.setInjectionPoint(injection_point)
new_script.setWorldId(QWebEngineScript.MainWorld)
try:
world = int(script.jsworld)
except ValueError:
try:
from qutebrowser.browser.webengine.webenginetab import _JS_WORLD_MAP
world = _JS_WORLD_MAP[usertypes.JsWorld[
script.jsworld.lower()]]
except KeyError:
log.greasemonkey.error(
"script {} has invalid value for '@qute-js-world'"
": {}".format(script.name, script.jsworld))
return
new_script.setWorldId(world)
new_script.setSourceCode(script.code())
new_script.setName("GM-{}".format(script.name))
new_script.setRunsOnSubFrames(script.runs_on_sub_frames)