Преглед на файлове

Add background to pizmet message

Pjotir преди 1 година
родител
ревизия
4c7f9435c3
променени са 2 файла, в които са добавени 15 реда и са изтрити 2 реда
  1. 14 1
      assets/js/background.js
  2. 1 1
      assets/js/contentscript_pfg.js

+ 14 - 1
assets/js/background.js

@@ -1,7 +1,7 @@
 document.getElementById("grabbutton").addEventListener("click", function () {
     browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
         browser.tabs
-            .sendMessage(tabs[0].id, "get")
+            .sendMessage(tabs[0].id, { action: "get" })
             .then(response => {
                 tablebody = document.getElementById("tablebody");
                 tablebody.innerHTML = "";
@@ -22,3 +22,16 @@ document.getElementById("grabbutton").addEventListener("click", function () {
             console.log(error);
         });
 });
+
+document.getElementById("inputbutton").addEventListener("click", function () {
+    browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
+        browser.tabs
+            .sendMessage(tabs[0].id, { action: "send", content: document.getElementById("tablebody") })
+            .then(response => {
+                console.log(response);
+            });
+    })
+        .catch(error => {
+            console.log(error);
+        });
+});

+ 1 - 1
assets/js/contentscript_pfg.js

@@ -7,7 +7,7 @@ function getInvoice() {
 }
 
 browser.runtime.onMessage.addListener(function (message, sender, sendResponse) {
-    if (message === "get") {
+    if (message["action"] === "get") {
         sendResponse(getInvoice());
     }
 });