diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 4d27d694a..3853de02c 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -24,6 +24,7 @@ Module attributes: _HANDLERS: The handlers registered via decorators. """ +import datetime import urllib.parse import qutebrowser @@ -158,6 +159,69 @@ def qute_bookmarks(_url): return 'text/html', html +@add_handler('history') +def qute_history(url): + """Handler for qute:history. Display history.""" + + # Get current date from query parameter, if not given choose today. + curr_date = datetime.date.today() + try: + for query in url.query().split("&"): + kv = query.split("=", 2) + if kv[0] == "date": + curr_date = datetime.datetime.strptime(kv[1], "%Y-%m-%d") + break + except Exception: + log.misc.debug("Invalid query string passed to qute://history") + + ONE_DAY = datetime.timedelta(days=1) + next_date = curr_date + ONE_DAY + prev_date = curr_date - ONE_DAY + + def history_iter(): + for item in objreg.get('web-history').history_dict.values(): + # Convert timestamp + item_date = None + try: + item_date = datetime.datetime.fromtimestamp(item.atime) + except Exception: + log.misc.error("Invalid timestamp {}.".format(item.atime)) + continue + + display_url = item.url.toDisplayString() + + # Skip items not on curr_date + # Skip redirects and items without title + # Skip qute:// links + has_no_title = len(item.title) <= 0 + is_internal = display_url.startswith("qute://") + is_redirect = item.redirect + is_not_today = ( + item_date.year != curr_date.year or + item_date.month != curr_date.month or + item_date.day != curr_date.day + ) + if (is_redirect or is_internal or has_no_title or is_not_today): + continue + + display_atime = item_date.strftime("%X") + yield (display_url, item.title, display_atime) + + history = [item for item in history_iter()] + try: + history = reversed(history) + except TypeError: # Python < 3.5 + history = reversed(list(history)) + + html = jinja.render('history.html', + title='History', + history=history, + curr_date=curr_date.strftime("%a, %d %B %Y"), + next_date=next_date.strftime("%Y-%m-%d"), + prev_date=prev_date.strftime("%Y-%m-%d")) + return 'text/html', html + + @add_handler('pyeval') def qute_pyeval(_url): """Handler for qute:pyeval.""" diff --git a/qutebrowser/html/history.html b/qutebrowser/html/history.html new file mode 100644 index 000000000..35bb79b39 --- /dev/null +++ b/qutebrowser/html/history.html @@ -0,0 +1,89 @@ +{% extends "base.html" %} + +{% block style %} +body { + background: #fefefe; + font-family: sans-serif; + margin: 0 auto; + max-width: 1440px; + padding-left: 20px; + padding-right: 20px; +} + +h1 { + color: #444; + font-weight: normal; +} + +table { + border-collapse: collapse; + width: 100%; +} + +td { + max-width: 50%; + padding: 2px 5px; + text-align: left; +} + +td.title { + word-break: break-all; +} + +td.time { + color: #555; + white-space: nowrap; +} + +a { + text-decoration: none; + color: #2562dc +} + +a:hover { + text-decoration: underline; +} + +tr:nth-child(odd) { + background-color: #f8f8f8; +} + +.date { + color: #888; + font-size: 14pt; + padding-left: 25px; +} + +.pagination-link { + display: inline-block; + margin-bottom: 10px; + margin-top: 10px; + padding-right: 10px; +} + +.pagination-link > a { + color: #333; + font-weight: bold; +} + +{% endblock %} + +{% block content %} + +
{{title}} | +{{time}} | +