]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/commitdiff
add an option to automatically purge history v1.5.0
authorMike Frysinger <vapier@gentoo.org>
Wed, 30 Jan 2013 03:32:03 +0000 (22:32 -0500)
committerMike Frysinger <vapier@gentoo.org>
Wed, 30 Jan 2013 03:40:09 +0000 (22:40 -0500)
_locales/en/messages.json
css/options.css
javascript/background.js
javascript/clearhistory.js
javascript/options.js
manifest.json
views/options.html

index e85b3a65e43385e4f4510941fcd8f0616eada343..52b1e3c0f0fc2477ea18f01978d135105d92da51 100644 (file)
@@ -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": {
index cdd6c74d388e1d2ca5b4907a76b3372f33566048..6e8cf7923cc87eb002bc52971786898e3c6ed799 100644 (file)
@@ -51,7 +51,8 @@ hr {
 }
 #opt-time,
 #opt-prompt,
-#opt-cookies {
+#opt-cookies,
+#opt-autoclear {
   background-color: white;
   clear: left;
   margin: 5px auto;
index ed52f43801d3a063ffae6a4db98157c4fe47ee69..9473cdaa6c40b99fd28d4d2b4e5c31c9bc2b83f3 100644 (file)
@@ -29,5 +29,7 @@ var CONSTANTS = {
    * @type {string}
    * @const
    */
-  NO: 'no'
+  NO: 'no',
+
+  CLEANER_ALARM: 'auto-cleaner'
 };
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');
 });
index 17139d59e576a283115724d70f99b41135b1ac96..f6dfcadec4533dfb4ef075ea94761270ee991bc3 100644 (file)
@@ -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);
 }
 
 /**
index a4ff4ff16bfdecd407c6523fe743399386a17f60..d089fb60ff01020ba2f89288ff5907404a15bced 100644 (file)
@@ -5,6 +5,7 @@
   "version": "1.5.0",
   "description": "__MSG_description__",
   "permissions": [
+    "alarms",
     "tabs",
     "history",
     "cookies",
index 9b909ebd728dc24ec7a0f89841ef4ef145fe9d35..6ac4f678c2c4349efd90a3875a470571d01d3508 100644 (file)
           </div>
         </div>
         <hr>
+        <div id="opt-autoclear">
+          <div class="opt-name">
+            <b>&nbsp;</b>
+          </div>
+          <div class="opt-value">
+            <div class="opt-option">
+              <input name="autoclear" class="opt-chk" type="checkbox">
+              <div class="opt-label" id="optionsAutoclear"></div>
+            </div>
+          </div>
+        </div>
+        <hr>
         <div id="optionsSaved">
           <b></b>
         </div>