]> 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 3766f6bf83e3a3d1adc440a3838e9f3b1f6b652e..7c9596f943ec287b28890ce8dd026176be9cb587 100644 (file)
@@ -72,16 +72,34 @@ function clearHistory() {
     chrome.history.deleteAll(didClearHistory);
   } else {
     // Create the range
+    var timeStart = localStorage['timeStart'] === CONSTANTS.YES;
     var now = (new Date).getTime();
+    var startTime = (now - time * 60 * 60 * 1000);  // time from hrs to ms
+    if (timeStart) {
+      var endTime = now;
+    } else {
+      var endTime = startTime;
+      startTime = 0;
+    }
     var range = {
-      startTime: (now - time * 60 * 60 * 1000),  // time from hrs to ms
-      endTime: now
+      startTime: startTime,
+      endTime: endTime
     };
     // Delete history in the range
     chrome.history.deleteRange(range, didClearHistory);
   }
 }
 
+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}
@@ -89,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');
@@ -99,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');
 });