background.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. document.getElementById("grabbutton").addEventListener("click", function () {
  2. browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
  3. browser.tabs
  4. .sendMessage(tabs[0].id, { action: "get" })
  5. .then((response) => {
  6. tablebody = document.getElementById("tablebody");
  7. tablebody.innerHTML = "";
  8. console.log(response);
  9. keys = Object.keys(response);
  10. keys.forEach(key => {
  11. tr = document.createElement("tr");
  12. td1 = document.createElement("td");
  13. td1.textContent = key;
  14. tr.appendChild(td1);
  15. td2 = document.createElement("td");
  16. td2.textContent = response[key].qty;
  17. tr.appendChild(td2);
  18. td3 = document.createElement("td");
  19. td3.textContent = response[key].cost;
  20. tr.appendChild(td3);
  21. td4 = document.createElement("td");
  22. td4.textContent = "$" + (parseFloat(response[key].qty * response[key].cost.substring(1)).toFixed(2));
  23. tr.appendChild(td4);
  24. tablebody.appendChild(tr);
  25. console.log(tr);
  26. });
  27. browser.storage.local.set(responsedata);
  28. });
  29. });
  30. })
  31. .catch(error => {
  32. console.log(error);
  33. });
  34. document.getElementById("inputbutton").addEventListener("click", function () {
  35. browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
  36. browser.tabs
  37. .sendMessage(tabs[0].id, { action: "send", content: document.getElementById("tablebody") })
  38. .then(response => {
  39. console.log(response);
  40. });
  41. })
  42. .catch(error => {
  43. console.log(error);
  44. });
  45. });