Skip to content

Commit

Permalink
Fixed stripe and other broken things
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnkr committed Nov 24, 2019
1 parent 374e830 commit a4c5b91
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autofill",
"version": "0.0.7",
"version": "0.0.8",
"description": "Open source autofill extension for Shopify, Supreme and Stripe",
"author": "Alex.#4321",
"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions src/inject/all.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
chrome.extension.sendMessage({}, function (response) {
chrome.storage.local.get({ 'profiles': [], 'selectedProfile': null, 'enabled': false }, (results) => {
if (results.enabled) {
let profile = results.profiles.find(profile => profile.id === results.selectedProfile);
window.onload = function () {
chrome.storage.local.get({ profiles: [], selectedProfile: null, enabled: false, settings: {} }, (results) => {
profile = results.profiles.find(profile => profile.id === results.selectedProfile);
settings = results.settings;

if (settings.enabled) {
if (profile) {
fill('email', profile.email);
fill('name', `${profile.firstName} ${profile.lastName}`);
Expand Down Expand Up @@ -32,7 +33,7 @@ chrome.extension.sendMessage({}, function (response) {
}
}
});
});
}

function fill(name, value) {
fillByAutocomplete(name, value);
Expand Down
5 changes: 2 additions & 3 deletions src/inject/shopify-card.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
let profile;
let settings;

chrome.extension.sendMessage({}, (response) => {
window.onload = function () {
chrome.storage.local.get({ profiles: [], selectedProfile: null, enabled: false, settings: {} }, (results) => {
profile = results.profiles.find(profile => profile.id === results.selectedProfile);
settings = results.settings;
Expand All @@ -23,7 +22,7 @@ chrome.extension.sendMessage({}, (response) => {
}
}
});
});
}

function fillField(id, value) {
let element = document.getElementById(id);
Expand Down
7 changes: 3 additions & 4 deletions src/inject/shopify.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
let profile;
let settings;

chrome.extension.sendMessage({}, (response) => {
chrome.storage.local.get({ profiles: [], selectedProfile: null, enabled: false, settings: {} }, (results) => {
window.onload = function () {
chrome.storage.local.get({ profiles: [], selectedProfile: null, enabled: false, settings: {} }, (results) => {
profile = results.profiles.find(profile => profile.id === results.selectedProfile);
settings = results.settings;

Expand Down Expand Up @@ -56,7 +55,7 @@ chrome.extension.sendMessage({}, (response) => {
}
}
});
});
}

chrome.extension.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'completeCheckout' && settings.shopify.completeCheckout) {
Expand Down
46 changes: 23 additions & 23 deletions src/inject/stripe.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
chrome.extension.sendMessage({}, function (response) {
chrome.storage.local.get({ 'profiles': [], 'selectedProfile': null, 'enabled': false}, (results) => {
if (results.enabled) {
let profile = results.profiles.find(profile => profile.id === results.selectedProfile);
window.onload = function () {
chrome.storage.local.get({ profiles: [], selectedProfile: null, enabled: false, settings: {} }, (results) => {
profile = results.profiles.find(profile => profile.id === results.selectedProfile);
settings = results.settings;

if (settings.enabled) {
if (profile) {
fillByName('cardnumber', profile.cardNumber);
fillByName('exp-date', `${profile.expiryMonth} / ${profile.expiryYear.slice(-2)}`);
fillByName('cvc', profile.cvv);
fillByName('postal', profile.zipcode);
let fields = {
'cardnumber': profile.cardNumber,
'exp-date': `${profile.expiryMonth} / ${profile.expiryYear.slice(-2)}`,
'cvc': profile.cvv,
'postal': profile.zipcode
}

Object.keys(fields).forEach(id => {
fillField(id, fields[id]);
});
}
}
});
});

};

function fillByName(name, value) {
let element = document.getElementsByName(name)[0];
function fillField(name, value) {
let element = document.getElementsByName(name)[0];
if (element) {
autofill(element, value);
}
}

function autofill(element, value) {
let event = document.createEvent("HTMLEvents");
event.initEvent('change', true, false);
element.focus();
element.value = value;
element.dispatchEvent(event);
element.blur();
element.focus();
element.value = value;
element.dispatchEvent(new Event('change'));
element.blur();
}
}
5 changes: 2 additions & 3 deletions src/inject/supreme.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
let profile;
let settings;

chrome.extension.sendMessage({}, (response) => {
window.onload = function () {
chrome.storage.local.get({ profiles: [], selectedProfile: null, enabled: false, settings: {} }, (results) => {
profile = results.profiles.find(profile => profile.id === results.selectedProfile);
settings = results.settings;
Expand Down Expand Up @@ -42,7 +41,7 @@ chrome.extension.sendMessage({}, (response) => {
}
}
});
});
}

function fillField(id, value, select = false) {
let element = document.getElementById(id);
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "SSS Autofill",
"description": "Open source autofill extension for Shopify, Supreme and Stripe",
"version": "0.0.7",
"version": "0.0.8",
"manifest_version": 2,
"icons": {
"48": "icons/icon_48.png",
Expand Down

0 comments on commit a4c5b91

Please sign in to comment.