From: Mike Frysinger Date: Wed, 30 Jan 2013 03:32:03 +0000 (-0500) Subject: add an option to automatically purge history X-Git-Tag: v1.5.0 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=6565d921d8384840180e5f61c09a6b51c2e2bc54;p=chrome-ext%2Fclearhistory-advance-fork.git add an option to automatically purge history --- diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e85b3a6..52b1e3c 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -18,6 +18,7 @@ "optionsPrompt": {"message": "Prompt before deleting"}, "optionsCookies": {"message": "Clear cookies too"}, "optionsSaved": {"message": "Preferences saved!"}, + "optionsAutoclear": {"message": "Automatically purge old entries"}, "confirmPrompt": {"message": "Are you sure you want to delete the history?"}, "notificationTitle": {"message": "History deleted successfully!"}, "notificationTime": { diff --git a/css/options.css b/css/options.css index cdd6c74..6e8cf79 100644 --- a/css/options.css +++ b/css/options.css @@ -51,7 +51,8 @@ hr { } #opt-time, #opt-prompt, -#opt-cookies { +#opt-cookies, +#opt-autoclear { background-color: white; clear: left; margin: 5px auto; diff --git a/javascript/background.js b/javascript/background.js index ed52f43..9473cda 100644 --- a/javascript/background.js +++ b/javascript/background.js @@ -29,5 +29,7 @@ var CONSTANTS = { * @type {string} * @const */ - NO: 'no' + NO: 'no', + + CLEANER_ALARM: 'auto-cleaner' }; diff --git a/javascript/clearhistory.js b/javascript/clearhistory.js index b2d2714..7c9596f 100644 --- a/javascript/clearhistory.js +++ b/javascript/clearhistory.js @@ -90,6 +90,16 @@ function clearHistory() { } } +function runCleaner() { + var clearCookies = localStorage['cookies'] || CONSTANTS.NO; + + if (clearCookies === CONSTANTS.YES) { + clearCookies(clearHistory); + } else { + clearHistory(); + } +} + /** * Executes when the user clicks the browser action. Uses stored values from * {@code localStorage} @@ -97,7 +107,6 @@ function clearHistory() { chrome.browserAction.onClicked.addListener(function(tab) { // Get the value from localStorage var showPrompt = localStorage['prompt'] || CONSTANTS.YES; - var clearCookies = localStorage['cookies'] || CONSTANTS.NO; // The confirmation message to ask var message = chrome.i18n.getMessage('confirmPrompt'); @@ -107,9 +116,18 @@ chrome.browserAction.onClicked.addListener(function(tab) { if (!confirm(message)) return; } - if (clearCookies === CONSTANTS.YES) { - clearCookies(clearHistory); - } else { - clearHistory(); - } + runCleaner(); +}); + +chrome.alarms.create(CONSTANTS.CLEANER_ALARM, { + // First fire 10 minutes from now. + 'when': Date.now() + (10 * 60 * 1000), + 'periodInMinutes': 24 * 60 +}); + +chrome.alarms.onAlarm.addListener(function(alarm) { + var autoCleaner = localStorage['autoclear'] || CONSTANTS.NO; + if (autoCleaner === CONSTANTS.YES) + runCleaner(); + console.log('running'); }); diff --git a/javascript/options.js b/javascript/options.js index 17139d5..f6dfcad 100644 --- a/javascript/options.js +++ b/javascript/options.js @@ -32,6 +32,7 @@ function init() { $('#optionsTimeFor')[0].innerText = chrome.i18n.getMessage('optionsTimeFor'); $('#optionsTimeStart')[0].innerText = chrome.i18n.getMessage('optionsTimeStart'); $('#optionsCookies')[0].innerText = chrome.i18n.getMessage('optionsCookies'); + $('#optionsAutoclear')[0].innerText = chrome.i18n.getMessage('optionsAutoclear'); $('#optionsSaved > b')[0].innerText = chrome.i18n.getMessage('optionsSaved'); // Bind all the callbacks @@ -52,11 +53,13 @@ function init() { var showPrompt = localStorage['prompt'] || (localStorage['prompt'] = CONSTANTS.YES); var clearCookies = localStorage['cookies'] || CONSTANTS.NO; + var autoClear = localStorage['autoclear'] || CONSTANTS.NO; $('input[name=timeStart]')[0].checked = (timeStart === CONSTANTS.YES); $('input[name=time][value="' + time + '"]')[0].checked = true; $('input[name=prompt]')[0].checked = (showPrompt === CONSTANTS.YES); $('input[name=cookies]')[0].checked = (clearCookies === CONSTANTS.YES); + $('input[name=autoclear]')[0].checked = (autoClear === CONSTANTS.YES); } /** diff --git a/manifest.json b/manifest.json index a4ff4ff..d089fb6 100644 --- a/manifest.json +++ b/manifest.json @@ -5,6 +5,7 @@ "version": "1.5.0", "description": "__MSG_description__", "permissions": [ + "alarms", "tabs", "history", "cookies", diff --git a/views/options.html b/views/options.html index 9b909eb..6ac4f67 100644 --- a/views/options.html +++ b/views/options.html @@ -93,6 +93,18 @@
+
+
+   +
+
+
+ +
+
+
+
+