]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blobdiff - javascript/clearhistory.js
add an option to automatically purge history
[chrome-ext/clearhistory-advance-fork.git] / javascript / clearhistory.js
index b2d27149114ce6e33e9c1812334a3691c43bd94c..7c9596f943ec287b28890ce8dd026176be9cb587 100644 (file)
@@ -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');
 });