]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blobdiff - javascript/popup.js
popup: move prompt from background page to popup page
[chrome-ext/clearhistory-advance-fork.git] / javascript / popup.js
diff --git a/javascript/popup.js b/javascript/popup.js
new file mode 100644 (file)
index 0000000..cba1e10
--- /dev/null
@@ -0,0 +1,25 @@
+/**
+ * @fileoverview Executes when the user clicks the browser action.
+ */
+
+import {CONSTANTS} from './background.js';
+
+async function init() {
+  const {prompt = CONSTANTS.YES} = await chrome.storage.sync.get('prompt');
+
+  if (prompt === CONSTANTS.YES) {
+    // The confirmation message to ask.
+    const message = chrome.i18n.getMessage('confirmPrompt');
+
+    if (!confirm(message)) {
+      window.close();
+      return;
+    }
+  }
+
+  // Notify background page to do the actual clear.
+  await chrome.runtime.sendMessage({action: 'runCleaner'});
+
+  window.close();
+}
+init();