diff --git a/LICENSE b/LICENSE index 35ad3fb..7c0bc25 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Rayquaza01 +Copyright (c) 2020 Klaus-Uwe Mitterer, 2017 Rayquaza01 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4da100f..2f86f63 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # HistoryCleaner -Firefox addon that deletes history older than a specified amount of days. +Firefox addon that deletes history whenever leaving a page. This addon is inspired by and is a WebExtension port of [Expire History By Days](https://addons.mozilla.org/en-US/firefox/addon/expire-history-by-days/). -Set the number of days to keep history items in the options page. Setting it to 0 will disable history deletion. The deletion will occur when the browser goes idle (after about 1 minute of inactivity). - -The icon is from [Material Design Icons](https://materialdesignicons.com/) - -[Link to addon page](https://addons.mozilla.org/en-US/firefox/addon/history-cleaner/) +The icon is from [Material Design Icons](https://materialdesignicons.com/) \ No newline at end of file diff --git a/extension/background.js b/extension/background.js index 43979d5..b4aaea1 100755 --- a/extension/background.js +++ b/extension/background.js @@ -1,71 +1,6 @@ -/* global defaultValues */ - -// brute force history items with visitCount or less visits -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 totalHistory.filter(item => item.visitCount <= visitCount); +async function deleteHistory(state) { + let end = new Date(); + browser.history.deleteRange({ startTime: 0, endTime: end }); } -async function deleteByVisits(visitCount, end) { - let history = await filterByVisits(visitCount, end); - for (let item of history) { - browser.history.deleteUrl({ url: item.url }); - } -} - -async function deleteOlderThan(state) { - if (state === "idle") { - 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); - end.setSeconds(0); - end.setMilliseconds(0); - end.setDate(end.getDate() - days); - let endDate = end.getTime(); - 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); - } - } - } else if (res.deleteMode === "visits") { - deleteByVisits(res.visitCount, Date.now()); - } - } -} - -async function setup() { - let res = await browser.storage.local.get(); - res = defaultValues(res, { - days: 0, - visitCount: 0, - deleteMode: "days" - }); - if (typeof res.days === "string") { - res.days = parseInt(res.days); - } - browser.storage.local.set(res); -} - -browser.idle.onStateChanged.addListener(deleteOlderThan); -browser.runtime.onInstalled.addListener(setup); +browser.webNavigation.onCompleted.addListener(deleteHistory); diff --git a/extension/manifest.json b/extension/manifest.json index f63f3c6..5ed190e 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,27 +1,18 @@ { "manifest_version": 2, "name": "History Cleaner", - "version": "1.2.2", - "description": "Deletes history older than a specified amount of days.", - "applications": { - "gecko": { - "id": "{a138007c-5ff6-4d10-83d9-0afaf0efbe5e}" - } - }, + "version": "1.2.2-kumi", + "description": "Deletes history on navigation.", + "icons": { "48": "icons/icon-48.png", "96": "icons/icon-96.png" }, "background": { - "scripts": ["webext_utilities.js", "background.js"] + "scripts": ["background.js"] }, "permissions": [ "history", - "storage", - "idle" - ], - "options_ui": { - "page": "options.html", - "browser_style": true - } + "webNavigation" + ] } diff --git a/extension/options.css b/extension/options.css deleted file mode 100644 index 7789e18..0000000 --- a/extension/options.css +++ /dev/null @@ -1,22 +0,0 @@ -body, input { - font-size: 1.25rem; -} - - -#settings { - width: 100%; -} - -tr { - border-bottom: 1px solid black; -} - -table > tr:last-child { - border-bottom: none; -} - -input { - height: 30px; - text-align: right; - width: 100%; -} diff --git a/extension/options.html b/extension/options.html deleted file mode 100644 index 7d30192..0000000 --- a/extension/options.html +++ /dev/null @@ -1,35 +0,0 @@ - - -
- - - - -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.)
-