]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blobdiff - javascript/clearhistory.js
add an option to run silently -- no notifications at all
[chrome-ext/clearhistory-advance-fork.git] / javascript / clearhistory.js
index 28eb2b060676ec161b554e177389f5316b24885a..b40f5958a187ef542f93230b1dd081a55a49f4df 100644 (file)
@@ -65,6 +65,9 @@ function clearDownloads(s) {
  * Callback for when history deletion is successful
  */
 function didClearHistory(s) {
+  if (s.notify !== CONSTANTS.YES)
+    return;
+
   var time = ~~(s.time) || CONSTANTS.DEFAULT_TIME;
   time = getUnitsForTime(time);
   var timeMsg = (time.time === -1) ? 'notificationTimeAll' :
@@ -72,14 +75,17 @@ function didClearHistory(s) {
                 'notificationTimeOlder';
   var timeString = chrome.i18n.getMessage(timeMsg, [time.time, time.units]);
   var message = chrome.i18n.getMessage('notificationBody', timeString);
-  var notification = webkitNotifications.createNotification(
-      chrome.extension.getURL('/images/icon48.png'),
-      chrome.i18n.getMessage('notificationTitle'),
-      message);
-  notification.show();
-  setTimeout(function() {
-    notification.cancel();
-  }, 5000);
+  var options = {
+    type: 'basic',
+    title: chrome.i18n.getMessage('notificationTitle'),
+    message: message,
+    iconUrl: chrome.extension.getURL('/images/icon128.png'),
+  };
+
+  var id = 'clearhistory advance notify';
+  chrome.notifications.clear(id, function(wasCleared) {
+    chrome.notifications.create(id, options, function(){});
+  });
 }
 
 /**
@@ -122,7 +128,7 @@ function clearAll(s) {
 
 function runCleaner() {
   var keys = [
-    'cookies', 'downloads', 'time', 'timeStart',
+    'cookies', 'downloads', 'time', 'timeStart', 'notify',
   ];
   chrome.storage.sync.get(keys, function(s) {
     if (s.cookies === CONSTANTS.YES) {