Created
November 26, 2018 23:40
-
-
Save sfoster/9c9230cba4e4cff1eb88423cd9547e51 to your computer and use it in GitHub Desktop.
Some form autofill scratchpad code to enter some test addresses and credit card details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is a JavaScript Scratchpad. | |
* | |
* Enter some JavaScript, then Right Click or choose from the Execute Menu: | |
* 1. Run to evaluate the selected text (Ctrl+R), | |
* 2. Inspect to bring up an Object Inspector on the result (Ctrl+I), or, | |
* 3. Display to insert the result in a comment after the selection. (Ctrl+L) | |
*/ | |
const cardBobsVisa = { | |
"cc-number": "4111111111111111", | |
"cc-exp-month": 1, | |
"cc-exp-year": 2020, | |
"cc-name": "Bob's Visa", | |
"cc-type": "visa", | |
"billingAddressGUID": "", | |
"cc-given-name": "Bob's", | |
"cc-family-name": "Visa", | |
"cc-exp": "2020-01", | |
}; | |
const addressTimBL = { | |
"given-name": "Timothy", | |
"additional-name": "John", | |
"family-name": "Berners-Lee", | |
organization: "World Wide Web Consortium", | |
"street-address": "32 Vassar Street\nMIT Room 32-G524", | |
"address-level2": "Cambridge", | |
"address-level1": "MA", | |
"postal-code": "02139", | |
country: "US", | |
tel: "+16172535702", | |
email: "[email protected]", | |
}; | |
const addressBob = { | |
"given-name": "Bob", | |
"additional-name": "B", | |
"family-name": "Bobness", | |
"street-address": "1 Bob Ave", | |
"address-level2": "Bobton", | |
"address-level1": "OR", | |
"postal-code": "97402", | |
"country": "US", | |
"name": "Bob B Bobness", | |
"address-line1": "1 Bob Ave", | |
"country-name": [ | |
"United States" | |
] | |
}; | |
const addressBoPeep = { | |
"given-name": "Bo", | |
"family-name": "Peep", | |
"street-address": "Hillock Ave", | |
"address-level2": "Tuffet", | |
"address-level1": "CA", | |
"postal-code": "91234", | |
"country": "US", | |
"name": "Bo Peep", | |
"address-line1": "Hillock Ave", | |
"country-name": [ | |
"United States" | |
] | |
}; | |
const addressIncomplete = { | |
"given-name": "Incomplete", | |
"address-level2": "a", | |
"postal-code": "11111", | |
"country": "US", | |
"name": "Incomplete", | |
"country-name": [ | |
"United States" | |
] | |
}; | |
async function addFormAutofillAddress(addressData) { | |
const {formAutofillStorage} = ChromeUtils.import( | |
"resource://formautofill/FormAutofillStorage.jsm", {}); | |
await formAutofillStorage.initialize(); | |
let guid = await formAutofillStorage.addresses.add(addressData); | |
return guid; | |
} | |
async function addFormAutofillCard(cardData) { | |
const {formAutofillStorage} = ChromeUtils.import( | |
"resource://formautofill/FormAutofillStorage.jsm", {}); | |
await formAutofillStorage.initialize(); | |
let guid = await formAutofillStorage.creditCards.add(cardData); | |
return guid; | |
} | |
async function prepopulatePaymentsRecords() { | |
const {formAutofillStorage} = ChromeUtils.import( | |
"resource://formautofill/FormAutofillStorage.jsm", {}); | |
await formAutofillStorage.initialize(); | |
formAutofillStorage.addresses.removeAll(); | |
formAutofillStorage.creditCards.removeAll(); | |
console.log("Cleared addresses & creditCards"); | |
let bobGuid = await addFormAutofillAddress(addressBob); | |
console.log(`Added address record: ${bobGuid}: ${addressBob["given-name"]}`); | |
let incompleteGuid = await addFormAutofillAddress(addressIncomplete); | |
console.log(`Added address record: ${incompleteGuid}: ${addressIncomplete["given-name"]}`); | |
let cardData = JSON.parse(JSON.stringify(cardBobsVisa)); | |
cardData.billingAddressGUID = bobGuid; | |
let cardGuid = await addFormAutofillCard(cardData); | |
console.log(`Added card record: ${cardGuid}: ${cardData["cc-name"]}`); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment