diff --git a/package.json b/package.json index d98ba2c..6d6b492 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/inject/all.js b/src/inject/all.js new file mode 100644 index 0000000..1b28755 --- /dev/null +++ b/src/inject/all.js @@ -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(); +} \ No newline at end of file diff --git a/src/inject/shopify.js b/src/inject/shopify.js index f5c04be..0d56df4 100644 --- a/src/inject/shopify.js +++ b/src/inject/shopify.js @@ -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); @@ -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); } } }); diff --git a/src/inject/stripe.js b/src/inject/stripe.js index 34465c8..b92667c 100644 --- a/src/inject/stripe.js +++ b/src/inject/stripe.js @@ -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(); } \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index 643aba7..80d4c43 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -24,6 +24,15 @@ "storage" ], "content_scripts": [ + { + "matches": [ + "https://*/*" + ], + "js": [ + "inject/all.js" + ], + "all_frames": true + }, { "matches": [ "https://js.stripe.com/*" diff --git a/src/popup/components/CountrySelect.vue b/src/popup/components/CountrySelect.vue index c607f7d..6b53f3e 100644 --- a/src/popup/components/CountrySelect.vue +++ b/src/popup/components/CountrySelect.vue @@ -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"] } }