<commit_before>var frontend = (function () {
  function getMeows(callback){
    var openGetReq = new XMLHttpRequest();
    openGetReq.onreadystatechange = function(){
         if (openGetReq.readyState == 4 && openGetReq.status == 200){
             callback(openGetReq.responseText);
         }
    };
    openGetReq.open("GET", "/meows", true);
    openGetReq.send();
  }

  function getMeowsCallback(data) {
    var catBasket = document.getElementsByClassName('cat-basket');
    var parsedMeow = JSON.parse(data);
    var growingBasket = "";
    for (var i = 0; i < parsedMeow.length; i++) {
        thisMeow = parsedMeow[i];
        growingBasket += meowBox(thisMeow.content, thisMeow.date.slice(0,10)+' '+thisMeow.date.slice(11,16));

    }

    catBasket[0].innerHTML = growingBasket;

    var deleteButtonArray = document.getElementsByClassName('delete-meow');

    for (var j = 0; j < deleteButtonArray.length; j++) {
      deleteButtonArray[j].addEventListener("click", deleteMeow);
    }

    function deleteMeow() {
      this.parentNode.parentNode.removeChild(this.parentNode);
    }
  }


  function meowBox(content, date) {
    return "<div class = \"meowBoxes\"><span>" + date + "</span><p>" + content + "</p><input class=\"delete-meow\" type=\"button\" value=\"DeleteMeow\"></div>";
  }

  getMeows(getMeowsCallback);

  //post meows
  var meowButton = document.getElementById('send-meow');

  meowButton.addEventListener("click", function() {postMeow(getMeowsCallback);});

  function postMeow(callback) {
    var openPostReq = new XMLHttpRequest();
    var stringifiedMeow = collectMeow();

    openPostReq.onreadystatechange = function()
    {

       if (openPostReq.readyState == 4 && openPostReq.status == 200)
       {
         var data = JSON.parse(openPostReq.responseText);
         callback(openPostReq.responseText);
       }
     };
    openPostReq.open("POST", "/", true);
    openPostReq.send(stringifiedMeow);
  }

  //create js object for date, cookie and content and stringify->send to backend
  function collectMeow() {
    var meowContent = document.getElementById('meow-content').value;
    var meowDate = new Date();
    var cookie = '';
    var meowObject = {
      cookie: cookie,
      date: meowDate,
      content: meowContent
    };
    return JSON.stringify(meowObject);

  }

  return {
    getMeows: getMeows,
    postMeow: postMeow,

    //deleteMeow: deleteMeow
  };
  }());<commit_msg>moving var declaration to top of function<commit_after>var frontend = (function() {

    // http request for meows
    function getMeows(callback) {
        var openGetReq = new XMLHttpRequest();
        openGetReq.onreadystatechange = function() {
            if (openGetReq.readyState == 4 && openGetReq.status == 200) {
                callback(openGetReq.responseText);
            }
        };
        openGetReq.open("GET", "/meows", true);
        openGetReq.send();
    }

    // callback to run each time we want to fetch meows
    function getMeowsCallback(data) {
        var catBasket = document.getElementsByClassName('cat-basket');
        var parsedMeow = JSON.parse(data);
        var growingBasket = "";
        var deleteButtonArray = document.getElementsByClassName('delete-meow');

        for (var i = 0; i < parsedMeow.length; i++) {
            thisMeow = parsedMeow[i];
            growingBasket += meowBox(thisMeow.content, thisMeow.date.slice(0, 10) + ' ' + thisMeow.date.slice(11, 16));

        }

        catBasket[0].innerHTML = growingBasket;
        
        for (var j = 0; j < deleteButtonArray.length; j++) {
            deleteButtonArray[j].addEventListener("click", deleteMeow);
        }

        function deleteMeow() {
            this.parentNode.parentNode.removeChild(this.parentNode);
        }
    }

    // Defining the html for our meows
    function meowBox(content, date) {
        return "<div class = \"meowBoxes\"><span>" + date + "</span><p>" + content + "</p><input class=\"delete-meow\" type=\"button\" value=\"DeleteMeow\"></div>";
    }

    //post meows
    var meowButton = document.getElementById('send-meow');
    meowButton.addEventListener("click", function() {
        postMeow(getMeowsCallback);
    });

    function postMeow(callback) {
        var openPostReq = new XMLHttpRequest();
        var stringifiedMeow = collectMeow();
        openPostReq.onreadystatechange = function() {
            if (openPostReq.readyState == 4 && openPostReq.status == 200) {
                var data = JSON.parse(openPostReq.responseText);
                callback(openPostReq.responseText);
            }
        };
        openPostReq.open("POST", "/", true);
        openPostReq.send(stringifiedMeow);
    }

    //create js object for date, cookie and content and stringify->send to backend
    function collectMeow() {
        var meowContent = document.getElementById('meow-content').value;
        var meowDate = new Date();
        var cookie = '';
        var meowObject = {
            cookie: cookie,
            date: meowDate,
            content: meowContent
        };
        return JSON.stringify(meowObject);
    }

    // THIS SHOULD BE ON PAGE LOAD OR SOMETHING //
    getMeows(getMeowsCallback);

    return {
        getMeows: getMeows,
        postMeow: postMeow,

        //deleteMeow: deleteMeow
    };
}());
{'fraction_non_alphanumeric': 0.1319796954314721, 'fraction_numerical': 0.00676818950930626, 'mean_word_length': 2.646333104866347, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3355254', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1570, 'n_words': 330}