From a4c5b919304716260979738e851f471cf2f514b1 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 Nov 2019 02:52:21 +0000 Subject: [PATCH] Fixed stripe and other broken things --- package.json | 2 +- src/inject/all.js | 11 ++++----- src/inject/shopify-card.js | 5 ++--- src/inject/shopify.js | 7 +++--- src/inject/stripe.js | 46 +++++++++++++++++++------------------- src/inject/supreme.js | 5 ++--- src/manifest.json | 2 +- 7 files changed, 38 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 10387ff..cddd9b2 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/inject/all.js b/src/inject/all.js index 9269866..cfe24f0 100644 --- a/src/inject/all.js +++ b/src/inject/all.js @@ -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}`); @@ -32,7 +33,7 @@ chrome.extension.sendMessage({}, function (response) { } } }); -}); +} function fill(name, value) { fillByAutocomplete(name, value); diff --git a/src/inject/shopify-card.js b/src/inject/shopify-card.js index a28d970..c57648c 100644 --- a/src/inject/shopify-card.js +++ b/src/inject/shopify-card.js @@ -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; @@ -23,7 +22,7 @@ chrome.extension.sendMessage({}, (response) => { } } }); -}); +} function fillField(id, value) { let element = document.getElementById(id); diff --git a/src/inject/shopify.js b/src/inject/shopify.js index 3a2bac2..729584c 100644 --- a/src/inject/shopify.js +++ b/src/inject/shopify.js @@ -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; @@ -56,7 +55,7 @@ chrome.extension.sendMessage({}, (response) => { } } }); -}); +} chrome.extension.onMessage.addListener((request, sender, sendResponse) => { if (request.action === 'completeCheckout' && settings.shopify.completeCheckout) { diff --git a/src/inject/stripe.js b/src/inject/stripe.js index b92667c..3acfa73 100644 --- a/src/inject/stripe.js +++ b/src/inject/stripe.js @@ -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(); + } } \ No newline at end of file diff --git a/src/inject/supreme.js b/src/inject/supreme.js index 5c30fd0..7026d51 100644 --- a/src/inject/supreme.js +++ b/src/inject/supreme.js @@ -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; @@ -42,7 +41,7 @@ chrome.extension.sendMessage({}, (response) => { } } }); -}); +} function fillField(id, value, select = false) { let element = document.getElementById(id); diff --git a/src/manifest.json b/src/manifest.json index 98e26c9..b8af761 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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",