diff options
author | Jimmy <jimmy@spalge.com> | 2018-01-20 16:31:10 +1300 |
---|---|---|
committer | Jimmy <jimmy@spalge.com> | 2018-03-03 15:02:42 +1300 |
commit | 87a0c2a7a70f2a6c1e73cf4f21682279d50cc8f3 (patch) | |
tree | de5bd664fc3dde33b4c8fca56cf821db097b5853 /qutebrowser/browser/greasemonkey.py | |
parent | 60e6d28eb11bd941692aa16cae06d788bc01ba4b (diff) | |
download | qutebrowser-87a0c2a7a70f2a6c1e73cf4f21682279d50cc8f3.tar.gz qutebrowser-87a0c2a7a70f2a6c1e73cf4f21682279d50cc8f3.zip |
Greasemonkey: indent source of required scripts
This is for the case where a script uses `@require` to pull down another
greasemonkey script. Since QWebEngineScript doesn't support `@require`
we pass scripts to it with any required ones pre-pended. To avoid
QWebEngineScript parsing the first metadata block, the one from the
required script, we indent the whole lot. Because the greasemonkey spec
says that the //==UserScript== text must start in the first column.
Diffstat (limited to 'qutebrowser/browser/greasemonkey.py')
-rw-r--r-- | qutebrowser/browser/greasemonkey.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/qutebrowser/browser/greasemonkey.py b/qutebrowser/browser/greasemonkey.py index 683985f54..d37340d88 100644 --- a/qutebrowser/browser/greasemonkey.py +++ b/qutebrowser/browser/greasemonkey.py @@ -25,6 +25,7 @@ import json import fnmatch import functools import glob +import textwrap import attr from PyQt5.QtCore import pyqtSignal, QObject, QUrl @@ -122,10 +123,11 @@ class GreasemonkeyScript: def add_required_script(self, source): """Add the source of a required script to this script.""" - # NOTE: If source also contains a greasemonkey metadata block then - # QWebengineScript will parse that instead of the actual one. - # Adding an indent to source would stop that. - self._code = "\n".join([source, self._code]) + # The additional source is indented in case it also contains a + # metadata block. Because we pass everything at once to + # QWebEngineScript and that would parse the first metadata block + # found as the valid one. + self._code = "\n".join([textwrap.indent(source, " "), self._code]) @attr.s |