Skip to content

Commit f32c1e6

Browse files
committedJul 28, 2019
Browser history algorithm adapted
1 parent ae5005b commit f32c1e6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed
 

‎javascripts/background/browserHistory.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function loadBrowserHistory(callback) {
2121
(intervalStart > lastUse ? intervalStart : lastUse) :
2222
intervalStart;
2323

24+
var tmpQueue = [];
2425
chrome.history.search({
2526
'text': '', // All entries
2627
'startTime': startTime,
@@ -42,17 +43,26 @@ function loadBrowserHistory(callback) {
4243
chrome.history.getVisits({
4344
url: item.url
4445
}, results => {
45-
queue.push(removeParamsFromUrl(item.url)); // Add to processing queue
46-
4746
// Update number of max. visits (because we want to visit all sites equally often)
4847
var count = results.filter(e => e.visitTime >= intervalStart).length;
4948
if (maxVisits < count)
5049
maxVisits = count;
5150

51+
tmpQueue.push([removeParamsFromUrl(item.url), count]); // Add to processing queue
52+
5253
storeInDatabase('visits', getKeyFromUrl(item.url), count, false, () => {
5354
inCallback();
5455
});
5556
});
56-
}, callback, 0);
57+
}, () => {
58+
// Sort by visit count
59+
tmpQueue.sort((a, b) => a[1] - b[1]);
60+
61+
// Insert urls into the real queue in sorted order
62+
for (const entry of tmpQueue)
63+
queue.push(entry[0]);
64+
65+
typeof callback === 'function' && callback();
66+
}, 0);
5767
});
5868
}

‎readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
## Lines of code
88
|Language |files |blank |comment |code|
99
|-----------------------------|---------------|-------------|------------------|----|
10-
|JavaScript | 21 | 215 | 556 |1059|
10+
|JavaScript | 21 | 217 | 558 |1065|
1111
|HTML | 2 | 10 | 1 | 116|
1212
|JSON | 2 | 0 | 0 | 84|
1313
|Bourne Shell | 1 | 13 | 8 | 38|
1414
|CSS | 2 | 4 | 6 | 34|
1515
|Markdown | 1 | 3 | 0 | 14|
1616
|- |- |- |- |- |
17-
|SUM: | 29 | 245 | 571 |1345|
17+
|SUM: | 29 | 247 | 573 |1351|

0 commit comments

Comments
 (0)
Please sign in to comment.