diff --git a/extension/background.js b/extension/background.js index 142d383..5a3b18c 100644 --- a/extension/background.js +++ b/extension/background.js @@ -1,20 +1,20 @@ +/* global defaultValues */ + async function filterByVisits(visitCount, end) { // brute force history items with visitCount or less visits let search = 1000; - while (true) { - const history = await browser.history.search({text: "", maxResults: search, startTime: 0, endTime: end}); - if (search > history.length) { - return history.filter(item => item.visitCount <= visitCount); - } else { - 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}); } + return history.filter(item => item.visitCount <= visitCount); } async function deleteByVisits(visitCount, end) { let history = await filterByVisits(visitCount, end); for (let item of history) { - browser.history.deleteURL({url: item.url}); + browser.history.deleteUrl({url: item.url}); } } @@ -23,6 +23,7 @@ async function deleteOlderThan(state) { const res = await browser.storage.local.get(); const days = parseInt(res.days) || 0; if (days !== 0) { + // get date x days ago let end = new Date(); end.setHours(0); end.setMinutes(0); @@ -30,21 +31,20 @@ async function deleteOlderThan(state) { end.setMilliseconds(0); end.setDate(end.getDate() - days); let endDate = end.getTime(); - if (mode === "days") { + if (res.deleteMode === "days") { + // delete by range OR visit count and range if (res.visitCount === 0) { browser.history.deleteRange({startTime: 0, endTime: endDate}); } else { deleteByVisits(res.visitCount, endDate); } } - } - if (mode === "visits") { + } else if (res.deleteMode === "visits") { deleteByVisits(res.visitCount, new Date().getTime()); } } } - async function setup() { let res = await browser.storage.local.get(); res = defaultValues(res, { diff --git a/extension/manifest.json b/extension/manifest.json index b85f486..f63f3c6 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -13,7 +13,7 @@ "96": "icons/icon-96.png" }, "background": { - "scripts": ["background.js"] + "scripts": ["webext_utilities.js", "background.js"] }, "permissions": [ "history", diff --git a/extension/options.css b/extension/options.css index fd834c7..7789e18 100644 --- a/extension/options.css +++ b/extension/options.css @@ -1,22 +1,20 @@ body, input { font-size: 1.25rem; } -#box { - align-items: center; - display: flex; - float: left; -} -#labels { - float: left; - width: 50%; -} + + #settings { - float: right; - width: 50%; + width: 100%; } -span { - line-height: 30px; + +tr { + border-bottom: 1px solid black; } + +table > tr:last-child { + border-bottom: none; +} + input { height: 30px; text-align: right; diff --git a/extension/options.html b/extension/options.html index e201746..7d30192 100644 --- a/extension/options.html +++ b/extension/options.html @@ -6,19 +6,28 @@
Number of days to keep history (set to 0 to disable) | ++ |
Maximum number of visits | ++ |
Delete Mode | ++ + | +
Setting the number of days will delete anything older than that amount of days. (Setting it to 7 will delete any history older than a week)
+Setting a number of visits will cause it to delete sites only with that amount of visits or less. (Setting it to 5 will delete any URLs from your history that you only visited 5 or less times.)
+If you have both a number of days and a number of visits set, it will delete history older than the number of days AND less than the number of visits. (Setting them to 7 and 5 will cause it to delete any is both older than a week AND has been visited 5 or less times.)