Skip to content

Commit

Permalink
Fixed email autofill on stripe, fixed some issues with Shopify autofill
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnkr committed Oct 27, 2019
1 parent 8f5d548 commit 42d1ca2
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 14 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.2",
"version": "0.0.3",
"description": "Open source autofill extension for Shopify, Supreme and Stripe",
"author": "Alex.#6254",
"scripts": {
Expand Down
63 changes: 63 additions & 0 deletions src/inject/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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);

if (profile) {
fill('email', profile.email);
fill('name', `${profile.firstName} ${profile.lastName}`);

fill('fullName', `${profile.firstName} ${profile.lastName}`);

fill('first-name', profile.firstName);
fill('firstname', profile.firstName);
fill('firstName', profile.firstName);

fill('last-name', profile.lastName);
fill('lastname', profile.lastName);
fill('lastName', profile.lastName);

fill('tel', profile.phoneNumber);

fill('address-line1', `${profile.address}, ${profile.address2}`);
fill('address-level2', profile.city);
fill('city', profile.city);
fill('state', profile.state);

fill('postal-code', profile.zipcode);
fill('zipcode', profile.zipcode);
fill('postcode', profile.zipcode);
fill('post-code', profile.zipcode);
}
}
});
});

function fill(name, value) {
fillByAutocomplete(name, value);
fillByName(name, value);
}

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

function fillByAutocomplete(name, value) {
let elements = document.querySelectorAll(`[autocomplete=${name}]`);

elements.forEach(function (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();
}
2 changes: 2 additions & 0 deletions src/inject/shopify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ chrome.extension.sendMessage({}, function (response) {
if (profile) {
autofill('checkout_email_or_phone', profile.email);
autofill('checkout[email_or_phone]', profile.email, true);
autofill('checkout[email]', profile.email, true);
autofill('checkout_shipping_address_first_name', profile.firstName);
autofill('checkout_shipping_address_last_name', profile.lastName);
autofill('checkout_shipping_address_address1', profile.address);
Expand All @@ -14,6 +15,7 @@ chrome.extension.sendMessage({}, function (response) {
autofill('checkout_shipping_address_country', profile.country);
autofill('checkout_shipping_address_province', profile.state);
autofill('checkout_shipping_address_zip', profile.zipcode);
autofill('checkout_shipping_address_phone', profile.phoneNumber);
}
}
});
Expand Down
29 changes: 17 additions & 12 deletions src/inject/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@ chrome.extension.sendMessage({}, function (response) {
let profile = results.profiles.find(profile => profile.id === results.selectedProfile);

if (profile) {
autofill('cardnumber', profile.cardNumber);
autofill('exp-date', `${profile.expiryMonth} / ${profile.expiryYear.slice(-2)}`);
autofill('cvc', profile.cvv);
autofill('postal', profile.zipcode);
fillByName('cardnumber', profile.cardNumber);
fillByName('exp-date', `${profile.expiryMonth} / ${profile.expiryYear.slice(-2)}`);
fillByName('cvc', profile.cvv);
fillByName('postal', profile.zipcode);
}
}
});
});

function autofill(name, value) {

function fillByName(name, value) {
let element = document.getElementsByName(name)[0];
if (element) {
let event = document.createEvent("HTMLEvents");
event.initEvent('change', true, false);
element.focus();
element.value = value;
element.dispatchEvent(event);
element.blur();
}
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();
}
9 changes: 9 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
"storage"
],
"content_scripts": [
{
"matches": [
"https://*/*"
],
"js": [
"inject/all.js"
],
"all_frames": true
},
{
"matches": [
"https://js.stripe.com/*"
Expand Down
2 changes: 1 addition & 1 deletion src/popup/components/CountrySelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
,"Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Pierre & Miquelon","Samoa","San Marino","Satellite","Saudi Arabia","Senegal","Serbia","Seychelles"
,"Sierra Leone","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain","Sri Lanka","St Kitts & Nevis","St Lucia","St Vincent","St. Lucia","Sudan"
,"Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga","Trinidad & Tobago","Tunisia"
,"Turkey","Turkmenistan","Turks & Caicos","Uganda","Ukraine","United Arab Emirates",,"United States Minor Outlying Islands","Uruguay"
,"Turkey","Turkmenistan","Turks & Caicos","Uganda","Ukraine","United Arab Emirates","United States Minor Outlying Islands","Uruguay"
,"Uzbekistan","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"]
}
}
Expand Down

0 comments on commit 42d1ca2

Please sign in to comment.