Skip to content

Instantly share code, notes, and snippets.

@anonrose
Last active January 4, 2017 20:41
Show Gist options
  • Save anonrose/b5ca9d6d259b8e2a44694324e3a7b72d to your computer and use it in GitHub Desktop.
Save anonrose/b5ca9d6d259b8e2a44694324e3a7b72d to your computer and use it in GitHub Desktop.
Fill em up
javascript:
var auto ={
email: 'kyle.rose@getg5.com',
firstname: 'This is a test',
econtent: 'This is a test from G5, your website provider. We are building a new website and need to confirm your leads are reaching the correct people. PLEASE FORWARD this email to kyle.rose@getg5.com to confirm receipt.',
test: 'Test',
zip: '12345',
telephone: '555-444-3333',
fillerup: function() {
var all_inputs = document.getElementsByTagName('input');
var all_selects = document.getElementsByTagName('select');
var all_textareas = document.getElementsByTagName('textarea');
var all_hcard = document.getElementsByClassName("contact-info h-card vcard widget");
var brandedname = this.getBrandedName(all_hcard);
for (var i = 0, max = all_selects.length; i < max; i++) {
var sel = all_selects[i];
if (sel.selectedIndex != -1&& sel.options[sel.selectedIndex].value) {
continue;
}
var howmany = 1;
if (sel.type == 'select-multiple') {
var howmany = 1 + this.getRand(sel.options.length - 1);
}
for (var j = 0; j < howmany; j++) {
var index = this.getRand(sel.options.length - 1);
sel.options[index].selected = 'selected';
}
}
for (var i = 0, max = all_textareas.length; i < max; i++) {
var ta = all_textareas[i];
ta.value = brandedname + ': ' + this.econtent;
}
for (var i = 0, max = all_inputs.length; i < max; i++) {
var inp = all_inputs[i];
var type = inp.getAttribute('type');
if(inp.required == true){
if (!type) {
type = 'text';
}
if (type == 'checkbox') {
inp.setAttribute('checked', 'checked');
}
if (type == 'radio') {
var to_update = true;var name = inp.name;var input_array = inp.form.elements[inp.name];
for (var j = 0; j < input_array.length; j++) {
if (input_array[j].checked) {
to_update = false;continue;
}
}
if (to_update) {
var index = this.getRand(input_array.length - 1);input_array[index].setAttribute('checked', 'checked');
}
}
if (type == 'email') {
inp.value = this.email;
}
if (type == 'tel') {
inp.value = this.telephone;
}
if (type == 'date') {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
var today = yyyy+'-'+mm+'-'+dd;
inp.value = today;
}
if (type == 'text') {
if (inp.name.indexOf('p-first-name') != -1) {
inp.value = this.firstname;
} else if (inp.name.indexOf('p-last-name') != -1) {
inp.value = brandedname;
} else if (inp.name.indexOf('p-name') != -1) {
inp.value = this.firstname + ' for: ' + brandedname;
} else if (inp.name.indexOf('p-tel') != -1) {
inp.value = this.telephone;
} else if (inp.name.indexOf('p-postal-code') != -1) {
inp.value = this.zip;
} else if (inp.name.indexOf('email') != -1) {
inp.value = this.email;
} else {
inp.value = this.test;
}
}
}
}
},
getBrandedName: function (all_hcard){
for (var i = 0, max = all_hcard.length; i < max; i++) {
var hcard = all_hcard[i];
brandedname = hcard.getElementsByClassName('p-name')[0].textContent;
}
return brandedname;
},
getRand: function (count) {
return Math.round(count * Math.random());
},
}; auto.fillerup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment