Program: Let Me Google That For You



function populateTextbox() {

    var strURL = ""
    var urlParams = ""
    var strURLParam = ""
    var strNewLink = ""
    var blnIsLink = 0;
    var letters

    // Grab URL
    strURL = window.location.search;

    // Find out if there's a query string variable called Link.
    blnIsLink = strURL.indexOf("Link");

    // If we find Link...
    if (blnIsLink == 1) {

        // Get the parameters in the URL (which should just be Link)
        urlParams = new URLSearchParams(strURL);
        // Assign the value of Link to strURLParam.
        strURLParam = urlParams.get("Link");
        // Create a new URL based off of that data.
        strNewLink = "https://www.google.com/search?q=" + strURLParam.replace(' ', '+');
        // Split up the words into individual letters for typing animation.
        letters = strURLParam.split("");


        // For each of the letters in the Link text...
        for (i = 0; i <= strURLParam.length - 1; i++) {
            // We have to set up this function to get the animation of the letters appearing.
            timeoutLoop(i, letters);
        };

        // Set the href of our link to be the modified URL.
        $('a[id*="lbLMGTFY"]').attr("href", strNewLink);

        // Add the swaying "Click Here." button
        setTimeout(function () {
            $('a[id*="lbLMGTFY"]').addClass("click-here");
        }, 3000);

    } else {
        // Do nothing.
    };

};

function timeoutLoop(i, letters) {
    setTimeout(function () {
        $('input[id*="tbLMGTFY"]').val($('input[id*="tbLMGTFY"]').val() + letters[i]);
    }, i * 200);
};