Start implementing prev/next

This commit is contained in:
Florian Bruhin 2014-04-30 18:01:03 +02:00
parent b9d7c7e7d9
commit 12b36de5b5
2 changed files with 23 additions and 0 deletions

View File

@ -278,6 +278,27 @@ class HintManager(QObject):
link = self._baseurl.resolved(link)
return link
def click_prevnext(self, frame, prev=False):
"""Click a "previous"/"next" element on the page."""
# First check for <link rel="prev(ious)|next">
self.target='normal'
elems = frame.findAllElements(webelem.SELECTORS['prevnext_rel'])
rel_values = ['prev', 'previous'] if prev else ['next']
for e in elems:
if e.attribute('rel') in rel_values:
self.click(e)
return
# Then check for regular links
elems = frame.findAllElements(webelem.SELECTORS['prevnext'])
option = 'prev-regexes' if prev else 'next-regexes'
for regex in config.get('hints', option):
for e in elems:
if regex.match(e.toPlainText()):
self.click(e)
return
message.error("No prev/forward links found!")
def start(self, frame, baseurl, mode='all', target='normal'):
"""Start hinting.

View File

@ -36,6 +36,8 @@ SELECTORS = {
'input[type=tel], input[type=number], '
'input[type=password], input[type=search], textarea'),
'url': '[src], [href]',
'prevnext_rel': 'link [role=link]',
'prevnext': 'a button [role=button]',
}
SELECTORS['editable_focused'] = ', '.join(