Skip to content

Commit

Permalink
Update to v5.1: Add to README and remove some bugs in PrinterPiExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-mous committed Sep 21, 2020
1 parent 5ab5b0a commit d8b35a9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
47 changes: 39 additions & 8 deletions PrinterPiExtension/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@
*/

/**
* User Settings
* Logo object
* @typedef {Object} Logo
* @property {string} data Image data
* @property {number} width Image width
* @property {number} height Image height
*/

/**
* Settings object
* @typedef {Object} Settings
* @property {string} ipAddress IP of printer
* @property {string} from Address of seller
* @property {string} fromLogo Name of return address logo (if any)
* @property {Logo} fromLogo Return address logo (if any)
* @property {string} messages Messages to add to receipt
* @property {boolean} saveFiles Save copies of receipts
* @property {string} saveFiles Save copies of receipts ("Y" for yes, "N" for no)
* @property {string} saveFilesLocation Path to where to save copies of receipts
* @property {string} autoParse Automatically parse page if the page is valid ("Y" for yes, "N" for no)
*/

/**
Expand Down Expand Up @@ -471,7 +480,7 @@ let getXButton = () => {
}

/**
* //Add an empty row to the table #items
* Add an empty row to the table #items
*
* @function addRowItems
*/
Expand All @@ -484,10 +493,24 @@ let addRowItems = () => { //Add an empty row to the table "items"
document.getElementById("items").appendChild(ele);
}

/**
* Show the Options page in a new tab
*
* @function showOptions
*/
let showOptions = () => {
chrome.tabs.create({'url': "/options.html" } );
}

/**
* Parse the webpage (run the background script, which triggers runtime.onMessage events - see below)
*
* @function parsePage
*/
let parsePage = () => {
chrome.extension.getBackgroundPage().chrome.tabs.executeScript(null, { file: './js/background.js' }); //Try to run the background script
}



window.onload = () => { //Add event listeners, etc.
Expand All @@ -500,23 +523,31 @@ window.onload = () => { //Add event listeners, etc.
let pkt = getPacket(settings);
if (pkt) printEnvelope(pkt);
});
}).catch(() => {

if (settings.autoParse == "Y") {
parsePage();
} else {
readStorageData(); //Read the current data and display it
}
}).catch((err) => {
console.log("Error while getting settings: " + err);
let done_msg = document.getElementById("done-msg");
done_msg.innerHTML = "Please configure the printer settings in the Setting page (via the button PrinterPi Settings below)";
done_msg.classList = "text-danger";
});
document.getElementById('save-button').addEventListener('click', setStorageData);
document.getElementById('parse-button').addEventListener('click', () => chrome.extension.getBackgroundPage().chrome.tabs.executeScript(null, { file: './js/background.js' })); //Execute the background parsing script
document.getElementById('parse-button').addEventListener('click', () => parsePage); //Execute the background parsing script
document.getElementById("items-row-btn").addEventListener("click", addRowItems);
document.getElementById("options-btn").addEventListener("click", showOptions);
document.getElementById('Shipping').addEventListener("change", validateInputs);
document.getElementById('Subtotal').addEventListener("change", validateInputs);
document.getElementById('Address').addEventListener("change", validateInputs);
readStorageData(); //Read the current data and display it
}

chrome.runtime.onMessage.addListener((msg) => { //Listen for messages and set the data accordingly
if (msg.error != null) { //Error message from background script
document.getElementById("more-info").innerHTML = "Manual entry mode - not a valid page to parse"; //Show the error message
document.getElementById("more-info").innerHTML = "Not a valid page to parse - showing stored data"; //Show the error message
readStorageData(); //Default to storage
} else {
setData({ //Set the data packet
to: msg.to,
Expand Down
2 changes: 1 addition & 1 deletion PrinterPiExtension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "PrinterPi",
"version": "4.0",
"version": "5.1",
"description": "Parse eBay Print Shipping Label or PayPal Activity pages and send the data to an application that controls a receipt printer",

"options_page": "options.html",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ To install the Chrome Extension, navigate to <a href="chrome://extensions">chrom

### Usage
#### Printing
Click on the extension on Google Chrome, navigate to either the eBay Print a shipping label page or the PayPal Activity page (make sure to open at least one transaction; the data gathered will appear if successful), ensure that the printer is up and running, press the "Parse Data" button to read the data off of the webpage, and finally press the "Print Receipt" button. If all is well, a message "Successfully sent data to the printer" will appear, the printer's light will start flashing and the paper will print. If not, please see Troubleshooting below. Also, there is a "Save Data" button to save the data into the extension, so that when it is reopened, the same settings will show. Finally, you can generate and print #10 size envelopes with the buyer's address, your address, and an optional custom logo by pressing the "Print Envelope" button. *Note: before using the printer for the first time, you will need to set up the options. Navigate to this page by using the button at the very bottom of the Chrome Extension and fill in the fields as directed (including the IP address from earlier)*
Click on the extension on Google Chrome, navigate to either the eBay Print a shipping label page or the PayPal Activity page (make sure to open at least one transaction; the data gathered will appear if successful), ensure that the printer is up and running, press the "Parse Data" button to read the data off of the webpage, and finally press the "Print Receipt" button. If all is well, a message "Successfully sent data to the printer" will appear, the printer's light will start flashing and the paper will print. If not, please see Troubleshooting below. Also, there is a "Save Data" button to save the data into the extension, so that when it is reopened, the same settings will show. Finally, you can generate and print #10 size envelopes with the buyer's address, your address, and an optional custom logo by pressing the "Print Envelope" button. *Note: before using the printer for the first time, you will need to set up the options. Navigate to this page by using the button at the very bottom of the Chrome Extension and fill in the fields as directed (including the IP address from earlier [written in the form of IP_ADDRESS:9321, where 9321 is the custom printer network port])*
#### Booting Up and Shutting Down
On boot, the printer will flash its LED slowly to indicate that the printer is ready for use. When you want to shut it down, press and hold the power button until the LED turns off. Then disconnect the power supply.
#### Note
Expand Down

0 comments on commit d8b35a9

Please sign in to comment.