diff --git a/README.md b/README.md index 306ff7c..dc479db 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # HistoryCleaner Firefox addon that deletes history older than a specified amount of days. + +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/) diff --git a/background.js b/background.js new file mode 100644 index 0000000..215d6ca --- /dev/null +++ b/background.js @@ -0,0 +1,15 @@ +browser.idle.onStateChanged.addListener(function(state) { + if (state == 'idle') { + browser.storage.local.get('days', function(res) { + if (res.days != 0) { + var end = new Date(); + end.setHours(0); + end.setMinutes(0); + end.setSeconds(0); + end.setMilliseconds(0); + end.setDate(end.getDate() - res.days); + browser.history.deleteRange({startTime: 0, endTime: end.getTime()}); + } + }); + } +}); diff --git a/icons/icon-48.png b/icons/icon-48.png new file mode 100644 index 0000000..e4044b4 Binary files /dev/null and b/icons/icon-48.png differ diff --git a/icons/icon-96.png b/icons/icon-96.png new file mode 100644 index 0000000..9e8e822 Binary files /dev/null and b/icons/icon-96.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..6b34b9f --- /dev/null +++ b/manifest.json @@ -0,0 +1,21 @@ +{ + "manifest_version": 2, + "name": "History Cleaner", + "version": "1", + "description": "Deletes history older than a specified amount of days.", + "icons": { + "48": "icons/icon-48.png", + "96": "icons/icon-96.png" + }, + "background": { + "scripts": ["background.js"] + }, + "permissions": [ + "history", + "storage", + "idle" + ], + "options_ui": { + "page": "options.html" + } +} diff --git a/options.html b/options.html new file mode 100644 index 0000000..0755c40 --- /dev/null +++ b/options.html @@ -0,0 +1,13 @@ + + + + + + +
+ + +
+ + + diff --git a/options.js b/options.js new file mode 100644 index 0000000..fd2d4a8 --- /dev/null +++ b/options.js @@ -0,0 +1,16 @@ +function saveOptions(e) { + browser.storage.local.set({ + days: document.querySelector("#days").value + }); + e.preventDefault(); +} + +function restoreOptions() { + var gettingItem = browser.storage.local.get('days'); + gettingItem.then((res) => { + document.querySelector("#days").value = res.days || '0'; + }); +} + +document.addEventListener('DOMContentLoaded', restoreOptions); +document.querySelector("form").addEventListener("submit", saveOptions);