Skip to content

Commit

Permalink
Port extension to Firefox.
Browse files Browse the repository at this point in the history
Changes:
- Created a folder named Firefox (for the Firefox version)
- Modified progressbar.js (added polyfill for window.requestAnimationFrame
  because the API is unavailable in Firefox)
- Modified manifest.json (rolled back to Manifest version 2 because of CORS
  issues and explicit permission issues, this is not an issue in Firefox as
  it is still properly supported, changed back from "host_permissions" to
  "permissions", added background page)
- Created background.html to include all the Javascript files that will run
  in the background (order of the import matters)
- Modified background.js to remove importScripts() (this is not supported in
  background pages in Firefox)
  • Loading branch information
tk-kushal authored and mlsad3 committed Jan 13, 2024
1 parent bdf4e82 commit ff2adf3
Show file tree
Hide file tree
Showing 17 changed files with 2,848 additions and 2,387 deletions.
5,107 changes: 2,720 additions & 2,387 deletions AmznHistoricChart/progressbar.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/AmazonIcon128.png
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/AmazonIcon32.png
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/AmazonIcon48.png
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/AmazonIcon64.png
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/AmazonIcon96.png
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/LICENSE_lrumap.txt
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/LICENSE_progressbar.txt
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/amazon.user.js
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/amazonccc.js
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/amazonfs.js
12 changes: 12 additions & 0 deletions AmznHistoricChartFirefox/background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="lru.js"></script>
<script src="amazonccc.js"></script>
<script src="amazonfs.js"></script>
<script src="background.js"></script>
</head>
<body>

</body>
</html>
54 changes: 54 additions & 0 deletions AmznHistoricChartFirefox/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Possible parameters for request:
* action: "xhttp" for a cross-origin HTTP request
* method: Default "GET"
* url : required, but not validated
* data : data to send in a POST request
* From http://stackoverflow.com/a/7699773/277601
* The callback function is called upon completion of the request
* NOTE: If you want to have some back-and-forths between the content script and background page,
* use chrome.runtime.connect and chrome.runtime.onConnect instead of sendMessage/onMessage
* */
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
// console.log("Starting Step 0: " + request.action);
if (request.action == "fakespot_xhttp") {
amazonfs.triage(request.url, callback);
return true; // prevents the callback from being called too early on return
} else if (request.action == "fakespot_clearcache") {
amazonfs.clearCache(request.url);
return true; // prevents the callback from being called too early on return
} else if (request.action == "amazonccc_xhttp") {
amazonccc.triage(request.asin, callback);
return true; // prevents the callback from being called too early on return
} else if (request.action == "camelimage_xhttp") {
amazoncamel.loadImageData(request, callback);
return true;
} else {
return false;
}
});

const amazoncamel = (() => {
// Refactored loadImageData without DOM
loadImageData = async (request, callback) => {
try {
const response = await fetch(request.url);
const blob = await response.blob();
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => {
const dataURL = reader.result;
callback(dataURL);
};
} catch (err) {
console.error("Error fetching image:", error);
callback(
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
);
// Handle errors appropriately, e.g., call the callback with an error message
}
};
return {
loadImageData,
};
})();
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/jquery-2.1.4.min.js
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/lru.js
49 changes: 49 additions & 0 deletions AmznHistoricChartFirefox/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "Historic Price Shopper: Amazon Price Tracking",
"version": "0.51",
"manifest_version": 2,
"description": "Adds Amazon.com historical price graph above the 'Add To Cart' button so you can monitor if it's a good time to buy.",
"icons": {
"128": "AmazonIcon128.png",
"96": "AmazonIcon96.png",
"64": "AmazonIcon64.png",
"48": "AmazonIcon48.png",
"32": "AmazonIcon32.png"
},
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": [
"https://www.amazon.com/*",
"https://smile.amazon.com/*",
"https://amazon.com/*",
"https://www.amazon.ca/*",
"https://amazon.ca/*",
"https://www.amazon.co.uk/*",
"https://amazon.co.uk/*"
],
"js": [
"jquery-2.1.4.min.js",
"lru.js",
"amazonfs.js",
"progressbar.js",
"amazon.user.js",
"amazonccc.js"
]
}
],
"permissions": [
"webRequest",
"webRequestBlocking",
"http://fakespot.com/",
"http://*.fakespot.com/",
"https://fakespot.com/",
"https://*.fakespot.com/",
"http://camelcamelcamel.com/",
"http://*.camelcamelcamel.com/",
"https://camelcamelcamel.com/",
"https://*.camelcamelcamel.com/"
]
}
1 change: 1 addition & 0 deletions AmznHistoricChartFirefox/progressbar.js

0 comments on commit ff2adf3

Please sign in to comment.