]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blobdiff - javascript/clearhistory.js
convert JS to ES6 modules
[chrome-ext/clearhistory-advance-fork.git] / javascript / clearhistory.js
index 28eb2b060676ec161b554e177389f5316b24885a..6cfa78562e94de461488ec642c1ce8bb13e4c0c1 100644 (file)
@@ -5,6 +5,9 @@
  * @author arunjit@google.com (Arunjit Singh)
  */
 
+import {CONSTANTS} from './background.js';
+import {getUnitsForTime} from './util.js';
+
 function getClearDate(s) {
   var time = ~~(s.time) || CONSTANTS.DEFAULT_TIME;
   if (time == -1)
@@ -65,6 +68,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 +78,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(){});
+  });
 }
 
 /**
@@ -100,7 +109,7 @@ function clearHistory(s) {
       var endTime = Date.now();
     } else {
       var endTime = time;
-      time = 0;
+      startTime = 0;
     }
     var range = {
       startTime: startTime,
@@ -122,7 +131,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) {