Skip to content

Commit

Permalink
Fixes #10 - Add support for reload balance pages. Also adds support f…
Browse files Browse the repository at this point in the history
…or checking accounts and adds some robustness to the number detection and nickname loading
  • Loading branch information
pip8786 committed Dec 26, 2018
1 parent 4651bad commit 56b341e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 32 deletions.
11 changes: 0 additions & 11 deletions AmazonCCNicknames.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="PHP Runtime" type="php">
<CLASSES>
<root url="jar://$APPLICATION_PLUGINS_DIR$/php/lib/php.jar!/stubs/standard" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$APPLICATION_PLUGINS_DIR$/php/lib/php.jar!/stubs/standard" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="library" name="chrome-DefinitelyTyped" level="application" />
</component>
</module>
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ Credit Card Nicknames for Amazon Chrome Extension
# Description
This is a small extension built after getting frustrated with the fact that Amazon doesn't allow you to give nicknames to your credit cards. It will sync them across your google account.

It was made for just the US site but could easily be adapted for other domains if there is any demand.

# Install
The extension can be found here: [Chrome Webstore] (https://chrome.google.com/webstore/detail/credit-card-nicknames-for/iodihdkgnjbpkdimohmpgbcfoioebbnf "Credit Card Nicknames for Amazon Chrome Extension")
The extension can be found here: [Chrome Webstore](https://chrome.google.com/webstore/detail/credit-card-nicknames-for/iodihdkgnjbpkdimohmpgbcfoioebbnf "Credit Card Nicknames for Amazon Chrome Extension")

# Security
The extension does not store the 4 digit numbers of the credit card, instead using a hash to associate the nickname with the card number.

# Releases
## 1.0.4 (Dec 25th, 2018)
- Fixed [#10](../../issues/10) - Support Reload Your Balance page
- Added support for checking accounts
- Made the script and popup more robust so hopefully fixes some issues people had with it showing at all.

## 1.0.3 (Feb 3rd, 2018)
- Fixed [#4](../../issues/4) - Payment options on amazon location changed, needed update in code
- Fixed [#5](../../issues/5) - Added smile support
Expand Down
36 changes: 33 additions & 3 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

"name": "Credit Card Nicknames for Amazon",
"short_name" :"CCNA",
"description": "This extension allows you to assign nick names to your credit cards on Amazon - Now for any country - And includes Smile!",
"version": "1.0.3",
"description": "This extension allows you to assign nick names to your credit cards (and checking accounts) on Amazon - Now for any country - And includes Smile!",
"version": "1.0.4",
"icons": {
"128": "images/ccna_icon128.png" },
"browser_action": {
Expand All @@ -16,62 +16,92 @@
"https://*.amazon.com/gp/wallet*",
"https://*.amazon.com/gp/buy/*",
"https://*.amazon.com/cpe/managepaymentmethods*",
"https://*.amazon.com/asv/reload*",
"https://*.amazon.com/asv/autoreload*",

"https://*.amazon.co.uk/gp/wallet*",
"https://*.amazon.co.uk/gp/buy/*",
"https://*.amazon.co.uk/cpe/managepaymentmethods*",
"https://*.amazon.co.uk/asv/reload*",
"https://*.amazon.co.uk/asv/autoreload*",

"https://*.amazon.fr/gp/wallet*",
"https://*.amazon.fr/gp/buy/*",
"https://*.amazon.fr/cpe/managepaymentmethods*",
"https://*.amazon.fr/asv/reload*",
"https://*.amazon.fr/asv/autoreload*",

"https://*.amazon.cn/gp/wallet*",
"https://*.amazon.cn/gp/buy/*",
"https://*.amazon.cn/cpe/managepaymentmethods*",
"https://*.amazon.cn/asv/reload*",
"https://*.amazon.cn/asv/autoreload*",

"https://*.amazon.in/gp/wallet*",
"https://*.amazon.in/gp/buy/*",
"https://*.amazon.in/cpe/managepaymentmethods*",
"https://*.amazon.in/asv/reload*",
"https://*.amazon.in/asv/autoreload*",

"https://*.amazon.co.jp/gp/wallet*",
"https://*.amazon.co.jp/gp/buy/*",
"https://*.amazon.co.jp/cpe/managepaymentmethods*",
"https://*.amazon.co.jp/asv/reload*",
"https://*.amazon.co.jp/asv/autoreload*",

"https://*.amazon.com.sg/gp/wallet*",
"https://*.amazon.com.sg/gp/buy/*",
"https://*.amazon.com.sg/cpe/managepaymentmethods*",
"https://*.amazon.com.sg/asv/reload*",
"https://*.amazon.com.sg/asv/autoreload*",

"https://*.amazon.de/gp/wallet*",
"https://*.amazon.de/gp/buy/*",
"https://*.amazon.de/cpe/managepaymentmethods*",
"https://*.amazon.de/asv/reload*",
"https://*.amazon.de/asv/autoreload*",

"https://*.amazon.it/gp/wallet*",
"https://*.amazon.it/gp/buy/*",
"https://*.amazon.it/cpe/managepaymentmethods*",
"https://*.amazon.it/asv/reload*",
"https://*.amazon.it/asv/autoreload*",

"https://*.amazon.nl/gp/wallet*",
"https://*.amazon.nl/gp/buy/*",
"https://*.amazon.nl/cpe/managepaymentmethods*",
"https://*.amazon.nl/asv/reload*",
"https://*.amazon.nl/asv/autoreload*",

"https://*.amazon.es/gp/wallet*",
"https://*.amazon.es/gp/buy/*",
"https://*.amazon.es/cpe/managepaymentmethods*",
"https://*.amazon.es/asv/reload*",
"https://*.amazon.es/asv/autoreload*",

"https://*.amazon.ca/gp/wallet*",
"https://*.amazon.ca/gp/buy/*",
"https://*.amazon.ca/cpe/managepaymentmethods*",
"https://*.amazon.ca/asv/reload*",
"https://*.amazon.ca/asv/autoreload*",

"https://*.amazon.com.mx/gp/wallet*",
"https://*.amazon.com.mx/gp/buy/*",
"https://*.amazon.com.mx/cpe/managepaymentmethods*",
"https://*.amazon.com.mx/asv/reload*",
"https://*.amazon.com.mx/asv/autoreload*",

"https://*.amazon.au/gp/wallet*",
"https://*.amazon.au/gp/buy/*",
"https://*.amazon.au/cpe/managepaymentmethods*",
"https://*.amazon.au/asv/reload*",
"https://*.amazon.au/asv/autoreload*",

"https://*.amazon.br/gp/wallet*",
"https://*.amazon.br/gp/buy/*",
"https://*.amazon.br/cpe/managepaymentmethods*"
"https://*.amazon.br/cpe/managepaymentmethods*",
"https://*.amazon.br/asv/reload*",
"https://*.amazon.br/asv/autoreload*"
]
}],
"permissions": [
Expand Down
34 changes: 24 additions & 10 deletions extension/src/content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const regex = /ending in\s*(\d{4})/;
const regex = /ending in\s*(\d{2,4})/;


// MutationSelectorObserver represents a selector and it's associated initialization callback.
Expand All @@ -16,7 +16,7 @@ msobservers.initialize = function (selector, callback) {
// called once per element.
let seen = [];
callbackOnce = function () {
if (seen.indexOf(this) == -1) {
if (seen.indexOf(this) === -1) {
seen.push(this);
$(this).each(callback);
}
Expand Down Expand Up @@ -52,32 +52,46 @@ observer.observe(document.documentElement, {childList: true, subtree: true, attr

function updateNicknames() {
chrome.storage.sync.get("nicknames", (data) => {
const nicknames = data["nicknames"] == undefined ? {} : data["nicknames"];
const nicknames = data["nicknames"] === undefined ? {} : data["nicknames"];
const appendNickname = function() {
$(this).find(".cc_nickname").remove();
const ccnum = CryptoJS.SHA256($(this).text().match(regex)[1]);
if(nicknames[ccnum] != undefined) {
const matches = $(this).text().match(regex);
let cardNumber = "0";
if(matches && matches.length >= 2) {
cardNumber = matches[1];
}
const ccnum = CryptoJS.SHA256(cardNumber);
if(nicknames[ccnum] !== undefined) {
const node = $("<span class='cc_nickname'></span>").text(" - "+nicknames[ccnum]);
$(this).append(node);
}
};

msobservers.initialize(".pmts-instrument-number-tail", appendNickname);
msobservers.initialize(".card-info span.a-color-secondary", appendNickname);
msobservers.initialize(".payment-row span.a-color-secondary", appendNickname);
msobservers.initialize("#payment-information span.a-color-secondary", appendNickname);
msobservers.initialize(".pmts-instrument-box span.a-color-secondary", appendNickname);
msobservers.initialize(".pmts-inst-tail", appendNickname);
});
}

function getCardNumbers(type) {
let cardNumbers = [];
let selector = null;
if (type == 1) {
if (type === 1) {
selector = $(".pmts-instrument-number-tail");
} else if (type == 2) {
selector = $(".card-info span.a-color-secondary");
} else if (type === 2) {
selector = $(".payment-row span.a-color-secondary");
} else if (type === 3) {
selector = $(".pmts-instrument-box span.a-color-secondary");
} else if (type === 4) {
selector = $(".pmts-inst-tail");
}
selector.each(function(){
cardNumbers.push($(this).text().match(regex)[1]);
const matches = $(this).text().match(regex);
if(matches && matches.length >= 2) {
cardNumbers.push(matches[1]);
}
});

chrome.runtime.sendMessage({
Expand Down
16 changes: 11 additions & 5 deletions extension/src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getCurrentTabUrl(callback) {
// If you want to see the URL of other tabs (e.g. after removing active:true
// from |queryInfo|), then the "tabs" permission is required to see their
// "url" properties.
console.assert(typeof url == 'string', 'tab.url should be a string');
console.assert(typeof url === 'string', 'tab.url should be a string');

callback(url);
});
Expand All @@ -52,21 +52,21 @@ function renderStatus(statusText) {
}

chrome.runtime.onMessage.addListener(function(request, sender) {
if (request.action == "getCards") {
if (request.action === "getCards") {
if (request.numbers.length) {
let nicknames = {};
chrome.storage.sync.get("nicknames", (data) => {
if(data["nicknames"] != undefined) {
if(data["nicknames"] !== undefined) {
nicknames = data["nicknames"];
}
renderStatus("Cards and nicknames:");
request.numbers.forEach((item) => {
const ccHash = CryptoJS.SHA256(item);
const oldValue = (nicknames[ccHash] != undefined) ? nicknames[ccHash] : "";
const oldValue = (nicknames[ccHash] !== undefined) ? nicknames[ccHash] : "";
const input = $("<input type='text' id='card"+ccHash+"' placeholder='Nickname'/>");
input.val(oldValue);
let node = $("<div><span>"+item+"</span> </div>").append(input);
input.change(()=>{
input.keyup(()=>{
nicknames[ccHash] = input.val();
chrome.storage.sync.set({"nicknames": nicknames}, () => {
console.log("Saved nicknames.");
Expand Down Expand Up @@ -95,6 +95,8 @@ const DOMAIN_REGEX = /^https:\/\/(smile|www)\.amazon\.[a-zA-Z.]{2,6}/;
const WALLET_REGEX = new RegExp(`${ DOMAIN_REGEX.source }/gp/wallet`);
const BUY_REGEX = new RegExp(`${ DOMAIN_REGEX.source }/gp/buy`);
const PAYMENT_REGEX = new RegExp(`${ DOMAIN_REGEX.source }/cpe/managepaymentmethods`);
const ASV_AUTO_REGEX = new RegExp(`${ DOMAIN_REGEX.source }/asv/autoreload/`);
const ASV_REGEX = new RegExp(`${ DOMAIN_REGEX.source }/asv/.*`);

document.addEventListener('DOMContentLoaded', function () {
getCurrentTabUrl(function (url) {
Expand All @@ -104,6 +106,10 @@ document.addEventListener('DOMContentLoaded', function () {
type = 1;
} else if (BUY_REGEX.test(url)) {
type = 2;
} else if (ASV_AUTO_REGEX.test(url)) {
type = 4;
} else if (ASV_REGEX.test(url)) {
type = 3;
}

if (type > 0) {
Expand Down

0 comments on commit 56b341e

Please sign in to comment.