Skip to content

Instantly share code, notes, and snippets.

@betsalel-williamson
Last active January 7, 2023 14:23
Show Gist options
  • Save betsalel-williamson/909ef1add8f07996248e2104f7f85971 to your computer and use it in GitHub Desktop.
Save betsalel-williamson/909ef1add8f07996248e2104f7f85971 to your computer and use it in GitHub Desktop.
HGTV Sweepstakes Helper
// For the first submission, full contact information is needed
// After the first submission, only email is needed
const contactInfo = {
email: "[email protected]",
firstName: "john",
lastName: "example",
address1: "address1",
city: "city",
state: "PA", // or "Pennsylvania"
zip: "12345",
mm: "January", // or "01"
dd: 01,
yyyy: 2021,
mvpd: "Other",
// Replace the "Other" string with one of the following options
// "Altice/Optimum",
// "Armstrong Cable Services",
// "AT&T U-verse",
// "Atlantic Broadband",
// "Blue Ridge Communications",
// "Bright House Networks/ Spectrum",
// "Cable ONE",
// "Charter/ Spectrum",
// "Comcast/Xfinity",
// "Cox",
// "DirecTV",
// "Dish Network",
// "Mediacom",
// "Midcontinent Communications",
// "RCN",
// "Service Electric",
// "Sling TV",
// "Suddenlink",
// "Time Warner Cable/ Spectrum",
// "Verizon FIOS",
// "WOW!",
// "Other",
// "Netflix/Hulu/Amazon Prime",
// "iTunes/Google Play/Amazon Instant Video",
// "Do Not Have Cable"
}
(async function submitInfo(contactInfo, autoSubmit = true) {
const inputId = "xReturningUserEmail";
const inputBtnId = "xCheckUser";
const submitBtnClassNames = "xButton xCTA xSubmit";
const fnId = "name_Firstname";
const lnId = "name_Lastname";
const addressId = "address_Address1";
const cityId = "address_City";
const stateId = "address_State";
const zipId = "address_Zip";
const monthId = "date_of_birth_month";
const dayId = "date_of_birth_day";
const yearId = "date_of_birth_year";
const mvpdId = "mvpd";
const mvpdDefault = "Do Not Have Cable";
function hasForm() {
return document.getElementById(fnId) != null;
}
function getValueFromOptions(elmId, tryVal, defaultVal = "") {
var options = [...document.getElementById(elmId).options];
return (
options.find((o) => o.value === tryVal || o.innerText === tryVal).value ||
defaultVal
);
}
function fillOutForm() {
document.getElementById(fnId).value = contactInfo.firstName;
document.getElementById(lnId).value = contactInfo.lastName;
document.getElementById(addressId).value = contactInfo.address1;
document.getElementById(cityId).value = contactInfo.city;
document.getElementById(stateId).value = getValueFromOptions(
stateId,
contactInfo.state
);
document.getElementById(zipId).value = contactInfo.zip;
document.getElementById(monthId).value = getValueFromOptions(
monthId,
contactInfo.mm
);
document.getElementById(dayId).value = contactInfo.dd;
document.getElementById(yearId).value = contactInfo.yyyy;
document.getElementById(mvpdId).value = getValueFromOptions(
mvpdId,
contactInfo.mvpd,
mvpdDefault
);
}
return new Promise((resolve) => {
document.getElementById(inputId).value = contactInfo.email;
document.getElementById(inputBtnId).click();
setTimeout(() => {
// First time entering, there will be a form to fill out
if (hasForm()) {
fillOutForm(contactInfo);
}
if (autoSubmit) {
document.getElementsByClassName(submitBtnClassNames)[0].click();
}
resolve();
}, 2 * 1000);
});
})(contactInfo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment