Skip to content

Commit

Permalink
Updates to Extension - v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-mous committed Sep 14, 2020
1 parent e6f3655 commit d375a66
Show file tree
Hide file tree
Showing 26 changed files with 615 additions and 1,061 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
55 changes: 0 additions & 55 deletions Extension/background.js

This file was deleted.

7 changes: 7 additions & 0 deletions Extension/css/bootstrap.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Extension/css/bootstrap.min.css.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Extension/css/font-awesome.min.css

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions Extension/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
body {
min-width: 400px;
background: #f9f9f9;
padding: 1px;
}

.title {
text-align: center;
font-size: 1.9em;
color: #d89200;
}

h2, h3, h4 {
text-align: center;
}

.datafield {
font-size: 1.2em;
}

.datatable {
font-size: 1.2em;
border: 1px solid black;
border-collapse: collapse;
}

.datatable thead {
font-weight: 800;
}

.datatable tr {
border: 1px solid black;
}

.datatable td {
border: 1px solid black;
}

.input-field {
text-align: center;
border: 1px solid #aaaaaa;
}

.input-field .btn-add-row {
border: none;
}

.btn {
width: 100%;
padding: 3px;
font-size: 1.3em;
background: #e8a202;
color: #000000;
border: 2px solid black;
border-radius: 7.5px;
}

.btn:hover {
background: #333333;
color: #ffffff;
}

.btn:active {
background: #888888;
}

.btn:disabled {
background: #eeeeee;
color: #aaaaaa;
}

input {
width: 100%;
}

table {
width: 100%;
}

.btn-add-row {
width: 100%;
padding: 0.2px;
margin: 0;
}
Binary file added Extension/fonts/fontawesome-webfont.woff2
Binary file not shown.
88 changes: 88 additions & 0 deletions Extension/js/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* background.js - Background code for PrinterPi extension web page
*
* Copyright (C) 2020 PolarPiBerry
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

try { //Try eBay
let address = document.querySelector("#shipToAddress").innerText;
let shipping = document.querySelectorAll(".BuyerPurchaseDetails--1nhS6")[3].children[1].innerText;
let total = document.querySelectorAll(".BuyerPurchaseDetails--1nhS6")[2].children[1].innerText;
let items = document.querySelectorAll(".PurchasedItem---CkHb");
let item_arr = [];
for (let i=0; i<items.length; i++) { //Iterate through the items
let itm = items[i].children[1];
item_arr.push({
desc: itm.children[0].innerText,
sku: "I",
qty: itm.children[1].children[0].innerText.slice(5),
price: itm.children[1].children[1].innerText
});
}
chrome.runtime.sendMessage({ //Send the first data
address: address,
shipping: shipping,
total: total,
items: item_arr
});
} catch (TypeError) {
try { //Otherwise, try PayPal
var transaction = document.querySelectorAll(".ppvx_row")[0]; //The main transaction (zero to only get the first transaction in list)
var trans_sub = transaction.querySelectorAll(".tdPurchaseDetails"); //Sub section containing items and purchase amount

var total_ele = trans_sub[0].getElementsByTagName("dd")[1];
var total = total_ele.innerText.includes("Purchase") ? total_ele.querySelectorAll(".ppvx_col-4")[0].innerText : "$0.00";

var total = "$0.00"; //Defaults
var shipping = "$0.00";

var data = trans_sub[0].getElementsByTagName("dd"); //Get the elements containing the purchase amounts
for (var i=0; i<data.length; i++) { //Iterate over all values, searching for shipping and total
if (data[i].innerText.includes("Shipping")) {
shipping = data[i].querySelectorAll(".ppvx_col-4")[0].innerText;
} else if (data[i].innerText.includes("Purchase")) {
total = data[i].querySelectorAll("ppvx_col-4")[0].innerText;
}
}

var addr_block = transaction.getElementsByTagName("dl")[1].getElementsByTagName("dd");
var addr = addr_block[0].innerText + "\n" + addr_block[1].innerText; //Combine the name and address

chrome.runtime.sendMessage({ //Send the first data
address: addr,
shipping: shipping,
total: total
});

var items = trans_sub[0].getElementsByTagName("dd")[0].querySelectorAll(".item"); //Items section
for (var i=0; i<items.length; i++) {
var sku = "I"; //No SKU field
var qty = "1"; //No QTY field
var desc = items[i].querySelectorAll(".ppvx_text--sm")[0].innerText; //Description is first field
var price = items[i].querySelectorAll(".ppvx_text--sm")[1].innerText; //Price is second field
chrome.runtime.sendMessage({
item: {
desc: desc,
sku: sku,
qty: qty,
price: price
}
});
}
} catch (TypeError) {
chrome.runtime.sendMessage({error: "Not a valid page to parse"});
}
}
7 changes: 7 additions & 0 deletions Extension/js/bootstrap.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Extension/js/bootstrap.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Extension/js/jquery.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit d375a66

Please sign in to comment.