smmerz / UAFF

// ==UserScript==
// @name        UAFF
// @namespace   MarchMadnessAutoFill
// @description UAFF
// @include     *.upickem.net/*
// @version     1.0.2
// @grant       none
// ==/UserScript==

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = 'expires='+d.toUTCString();
    //document.cookie = cname + '=' + cvalue + '; ' + expires;
    document.cookie = cname + '=' + cvalue + '; ' +'Domain=upickem.net; Path=/;'+ expires;

};

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
};

function checkCookie(cname,type,directions) {
    var cookie = getCookie(cname);
    if (type == 'F'){
        if (cookie != "") {
            if (document.getElementById(cname)){
            document.getElementById(cname).value=cookie;};
        } else {
            newcookie = prompt(directions, "");
            if (newcookie != "" && newcookie != null) {
                setCookie(cname, newcookie, 365);
                document.getElementById(cname).value=newcookie;
            }
        }
    }
};

function uncheckBoxes(classname) {
    var boxes = document.getElementsByClassName(classname);
//    console.log(boxes.length)
    var box;
//    console.log('Boxes'+boxes)
    for (box=0; box < boxes.length; box++){
//        console.log('Box',box)
        boxname = boxes[box].id;
        boxnumberset = boxname.split("-")
        boxnumber = boxname.split("-").pop()
//        console.log('IDBoxname'+boxname)
//        console.log(boxnumberset)
//        console.log('Last Element'+boxnumber)
        if (isNaN(boxnumber)==false){
//            console.log('here')
//            console.log('chkGlobal'+boxnumber);
            document.getElementById('chkGlobal'+boxnumber).value="1";
        }
    }
};
    

window.onload = function(){
    checkCookie("txtFirstName",'F','Type your first name:');
    checkCookie("txtLastName","F",'Type your last name:');
    if (document.getElementById("rdoTooYoungN")){
        document.getElementById("rdoTooYoungN").click();}
    if (document.getElementById("cboBirthDateMonth")){
        document.getElementById("cboBirthDateMonth").value=checkCookie("cboBirthDateMonth",'F','Type the NUMBER of the MONTH that you were born on');}
    if (document.getElementById("cboBirthDateDay")){
        document.getElementById("cboBirthDateDay").value=checkCookie("cboBirthDateDay",'F','Type the NUMBER of the DAY of the month that you were born on');}    
    if (document.getElementById("cboBirthDateYear")){
        document.getElementById("cboBirthDateYear").value=checkCookie("cboBirthDateYear",'F','Type the NUMBER of the YEAR that you were born on');}    
    if (document.getElementById("cboSex")){
        document.getElementById("cboSex").value=checkCookie("cboSex",'F','Please type 0 for Male or 1 for Female');}    
    checkCookie("txtUserNameReg",'F','Type your desired username');
    checkCookie("txtEmailAddress",'F','Type your email address');
    checkCookie("txtConfirmEmail",'F','Confirm your email address');
    checkCookie("txtPhone",'F','Type your phone number');
    checkCookie("txtCity",'F','Type your City');
    if (document.getElementById("cboState")){
        document.getElementById("cboState").value='ME';}
    checkCookie("txtPostalCode",'F','Type your postal code');
    checkCookie("txtExtraField",'F','Type your mailing address');
    checkCookie("txtPasswordReg",'F','Type your password (8-20 characters)');
    checkCookie("txtConfirmPasswordReg",'F','Confirm your password');
    uncheckBoxes("UPE-FormField UPE-Checkbox UPE-Optin");
    if (document.getElementById("chkNationalOptIn")){
        document.getElementById("chkNationalOptIn").click();}
    if (document.getElementById("chkReminder")){
        document.getElementById("chkReminder").click();}
    if (document.getElementById("chkNoEmails")){
        document.getElementById("chkNoEmails").click();}
    if (document.getElementById("ckAgree")){
        document.getElementById("ckAgree").click();}
    
};

function resetCookies(){
    setCookie("txtFirstName",'',1);
    setCookie("txtLastName","",1);
    setCookie("cboBirthDateMonth","",1);
    setCookie("cboBirthDateDay","",1);
    setCookie("cboBirthDateYear","",1);
    setCookie("cboSex","",1);
    setCookie("txtUserNameReg",'',1);
    setCookie("txtEmailAddress",'',1);
    setCookie("txtConfirmEmail",'',1);
    setCookie("txtPhone",'',1);
    setCookie("txtCity",'',1);
    setCookie("txtPostalCode",'',1);
    setCookie("txtExtraField",'',1);
    setCookie("txtPasswordReg",'',1);
    setCookie("txtConfirmPasswordReg",'',1);
}
//setCookie("txtConfirmEmail",'',1);

//resetCookies()

//setCookie("txtPasswordReg",'',1);
//setCookie("txtConfirmPasswordReg",'',1);