diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index b6b95de53..06417518c 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -179,8 +179,17 @@ def qute_history(url): end_time = start_time - 24*60*60 # end is 24hrs earlier than start + # when history_dict is not reversed, we need to keep track of last item + # so that we can yield its atime + last_item = None + for item in history: - # Abort/continue as early as possible + # Skip redirects + # Skip qute:// links + if item.redirect or item.url.scheme() == 'qute': + continue + + # Skip items out of time window item_newer = item.atime > start_time item_older = item.atime <= end_time if reverse: @@ -189,6 +198,7 @@ def qute_history(url): # abort if item is older than start_time+24hr # skip if item is newer than start if item_older: + yield {"next": int(item.atime)} return if item_newer: continue @@ -198,15 +208,12 @@ def qute_history(url): # abort if item is newer than start_time # skip if item is older than start_time+24hrs if item_older: + last_item = item continue if item_newer: + yield {"next": int(last_item.atime)} return - # Skip redirects - # Skip qute:// links - if item.redirect or item.url.scheme() == 'qute': - continue - # Use item's url as title if there's no title. item_url = item.url.toDisplayString() item_title = item.title if item.title else item_url @@ -214,6 +221,9 @@ def qute_history(url): yield {"url": item_url, "title": item_title, "time": item_time} + # if we reached here, we had reached the end of history + yield {"next": -1} + if url.path() == '/data': # Use start_time in query or current time. try: diff --git a/qutebrowser/html/history.html b/qutebrowser/html/history.html index ba64316e4..9523b10de 100644 --- a/qutebrowser/html/history.html +++ b/qutebrowser/html/history.html @@ -28,6 +28,19 @@ table { text-align: left; } +#load { + color: #555; + font-weight: bold; + text-decoration: none; +} + +#eof { + color: #aaa; + margin-bottom: 30px; + text-align: center; + width: 100%; +} + .session-separator { color: #aaa; height: 40px; @@ -43,6 +56,8 @@ table { var global = { // The last history item that was seen. lastItem: null, + // The next time to load + nextTime: null, // The cutoff interval for session-separator (30 minutes) SESSION_CUTOFF: 30*60 }; @@ -144,14 +159,25 @@ var getJSON = function(url, callback) { */ var loadHistory = function() { url = "qute://history/data"; - if (global.lastItem !== null) { - startTime = parseInt(global.lastItem.time) - 1; + if (global.nextTime !== null) { + startTime = global.nextTime; url = "qute://history/data?start_time=" + startTime.toString(); } getJSON(url, function(status, history) { if (history !== undefined) { for (item of history) { + if (item.next === -1) { + // Reached end of history + window.onscroll = null; + document.getElementById('eof').style.display = "block" + document.getElementById('load').style.display = "none" + continue; + } else if (item.next !== undefined) { + global.nextTime = parseInt(item.next); + continue; + } + atime = new Date(parseInt(item.time)*1000); var session = getSessionNode(atime); var row = makeHistoryRow(item.url, item.title, atime.toLocaleTimeString()); @@ -166,10 +192,11 @@ var loadHistory = function() { {% block content %}