Filter javascript-links from hinting
This commit is contained in:
parent
fec353809b
commit
1e27f5537d
@ -86,6 +86,9 @@ class HintManager(QObject):
|
|||||||
|
|
||||||
Class attributes:
|
Class attributes:
|
||||||
SELECTORS: CSS selectors for the different highlighting modes.
|
SELECTORS: CSS selectors for the different highlighting modes.
|
||||||
|
FILTERS: A dictionary of filter functions for the modes.
|
||||||
|
The filter for "links" filters javascript:-links and a-tags
|
||||||
|
without "href".
|
||||||
HINT_CSS: The CSS template to use for hints.
|
HINT_CSS: The CSS template to use for hints.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -124,6 +127,11 @@ class HintManager(QObject):
|
|||||||
"url": "[src], [href]",
|
"url": "[src], [href]",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILTERS = {
|
||||||
|
"links": (lambda e: e.hasAttribute("href") and
|
||||||
|
urlutils.qurl(e.attribute("href")).scheme() != "javascript"),
|
||||||
|
}
|
||||||
|
|
||||||
HINT_CSS = """
|
HINT_CSS = """
|
||||||
color: {config[colors][hints.fg]};
|
color: {config[colors][hints.fg]};
|
||||||
background: {config[colors][hints.bg]};
|
background: {config[colors][hints.bg]};
|
||||||
@ -325,8 +333,6 @@ class HintManager(QObject):
|
|||||||
if not link:
|
if not link:
|
||||||
return None
|
return None
|
||||||
link = urlutils.qurl(link)
|
link = urlutils.qurl(link)
|
||||||
if link.scheme() == "javascript":
|
|
||||||
return None
|
|
||||||
if link.isRelative():
|
if link.isRelative():
|
||||||
link = self._baseurl.resolved(link)
|
link = self._baseurl.resolved(link)
|
||||||
return link
|
return link
|
||||||
@ -343,12 +349,14 @@ class HintManager(QObject):
|
|||||||
hint_strings_updated: Emitted to update keypraser.
|
hint_strings_updated: Emitted to update keypraser.
|
||||||
set_mode: Emitted to enter hinting mode
|
set_mode: Emitted to enter hinting mode
|
||||||
"""
|
"""
|
||||||
selector = HintManager.SELECTORS[mode]
|
|
||||||
self._target = target
|
self._target = target
|
||||||
self._baseurl = baseurl
|
self._baseurl = baseurl
|
||||||
elems = self._frame.findAllElements(selector)
|
elems = self._frame.findAllElements(self.SELECTORS[mode])
|
||||||
|
filterfunc = self.FILTERS.get(mode, lambda e: True)
|
||||||
visible_elems = []
|
visible_elems = []
|
||||||
for e in elems:
|
for e in elems:
|
||||||
|
if not filterfunc(e):
|
||||||
|
continue
|
||||||
rect = e.geometry()
|
rect = e.geometry()
|
||||||
if (not rect.isValid()) and rect.x() == 0:
|
if (not rect.isValid()) and rect.x() == 0:
|
||||||
# Most likely an invisible link
|
# Most likely an invisible link
|
||||||
|
Loading…
Reference in New Issue
Block a user