]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blobdiff - javascript/clearhistory.js
convert to MV3
[chrome-ext/clearhistory-advance-fork.git] / javascript / clearhistory.js
index b40f5958a187ef542f93230b1dd081a55a49f4df..bae6a7a09f06ced0edc577ea35d5bb58771698d3 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)
@@ -106,7 +109,7 @@ function clearHistory(s) {
       var endTime = Date.now();
     } else {
       var endTime = time;
-      time = 0;
+      startTime = 0;
     }
     var range = {
       startTime: startTime,
@@ -140,24 +143,14 @@ function runCleaner() {
 }
 
 /**
- * Executes when the user clicks the browser action. Uses stored values from
- * {@code localStorage}
+ * Callback from other pages (like the popup).
  */
-chrome.browserAction.onClicked.addListener(function(tab) {
-  // Get the value from localStorage
-  chrome.storage.sync.get('prompt', function(s) {
-  var showPrompt = s.prompt || CONSTANTS.YES;
-
-  // The confirmation message to ask
-  var message = chrome.i18n.getMessage('confirmPrompt');
-
-  // Clear cookies, and then clear the history
-  if (showPrompt === CONSTANTS.YES) {
-    if (!confirm(message))
-      return;
+chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
+  switch (request?.action) {
+    case 'runCleaner':
+      runCleaner();
+      break;
   }
-  runCleaner();
-  });
 });
 
 chrome.alarms.get(CONSTANTS.CLEANER_ALARM, function(a) {