summaryrefslogtreecommitdiff
path: root/qutebrowser/browser/greasemonkey.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-02-25 09:56:18 +0100
committerFlorian Bruhin <me@the-compiler.org>2019-02-25 09:56:18 +0100
commit94542c5f780aae78612a112b7be6f78da97b736f (patch)
tree56e06ce089d39b7f6f217d032b16b0737c539c93 /qutebrowser/browser/greasemonkey.py
parentb10366ec3a4e600e0851086bd200f8fb11160d5a (diff)
parent6dd978ae05a4fb0525967c390ece2e51bbdb2a1a (diff)
downloadqutebrowser-94542c5f780aae78612a112b7be6f78da97b736f.tar.gz
qutebrowser-94542c5f780aae78612a112b7be6f78da97b736f.zip
Merge branch 'greasemonkey-quirks'
Diffstat (limited to 'qutebrowser/browser/greasemonkey.py')
-rw-r--r--qutebrowser/browser/greasemonkey.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/qutebrowser/browser/greasemonkey.py b/qutebrowser/browser/greasemonkey.py
index 7ef1f0ff2..07fa8d581 100644
--- a/qutebrowser/browser/greasemonkey.py
+++ b/qutebrowser/browser/greasemonkey.py
@@ -31,7 +31,8 @@ import attr
from PyQt5.QtCore import pyqtSignal, QObject, QUrl
from qutebrowser.utils import (log, standarddir, jinja, objreg, utils,
- javascript, urlmatch, version, usertypes)
+ javascript, urlmatch, version, usertypes,
+ qtutils)
from qutebrowser.api import cmdutils
from qutebrowser.browser import downloads
from qutebrowser.misc import objects
@@ -116,6 +117,40 @@ class GreasemonkeyScript:
script.includes = ['*']
return script
+ def force_document_end(self):
+ """Check whether to force @run-at document-end.
+
+ This needs to be done on QtWebEngine with Qt 5.12 for known-broken
+ scripts.
+
+ On Qt 5.12, accessing the DOM isn't possible with "@run-at
+ document-start". It was documented to be impossible before, but seems
+ to work fine.
+
+ However, some scripts do DOM access with "@run-at document-start". Fix
+ those by forcing them to use document-end instead.
+ """
+ if objects.backend != usertypes.Backend.QtWebEngine:
+ return False
+ elif not qtutils.version_check('5.12', compiled=False):
+ return False
+
+ broken_scripts = [
+ ('http://userstyles.org', None),
+ ('https://github.com/ParticleCore', 'Iridium'),
+ ]
+ return any(self._matches_id(namespace=namespace, name=name)
+ for namespace, name in broken_scripts)
+
+ def _matches_id(self, *, namespace, name):
+ """Check if this script matches the given namespace/name.
+
+ Both namespace and name can be None in order to match any script.
+ """
+ matches_namespace = namespace is None or self.namespace == namespace
+ matches_name = name is None or self.name == name
+ return matches_namespace and matches_name
+
def code(self):
"""Return the processed JavaScript code of this script.