Fix filter by visits

This commit is contained in:
Joe Jarvis 2020-02-08 11:22:54 -05:00
parent 4c6721aabb
commit b19389776d

25
extension/background.js Normal file → Executable file
View file

@ -1,14 +1,23 @@
/* global defaultValues */
async function filterByVisits(visitCount, end) {
// brute force history items with visitCount or less visits
let search = 1000;
let history = await browser.history.search({text: "", maxResults: search, startTime: 0, endTime: end});
while (search < history.length) {
search += 1000;
history = await browser.history.search({text: "", maxResults: search, startTime: 0, endTime: end});
async function filterByVisits(visitCount, end) {
let start = 0;
let totalHistory = [];
let history = await browser.history.search({
text: "",
startTime: start,
endTime: end,
maxResults: 1
});
while (history.length > 0) {
totalHistory = totalHistory.concat(history);
start = history[history.length - 1].lastVisitTime + 1;
history = await browser.history.search({text: "", startTime: start, endTime: end, maxResults: 1});
}
return history.filter(item => item.visitCount <= visitCount);
return totalHistory.filter(item => item.visitCount <= visitCount);
}
async function deleteByVisits(visitCount, end) {
@ -40,7 +49,7 @@ async function deleteOlderThan(state) {
}
}
} else if (res.deleteMode === "visits") {
deleteByVisits(res.visitCount, new Date().getTime());
deleteByVisits(res.visitCount, Date.now());
}
}
}