<commit_before>var tablesArray = document.getElementsByTagName("table");
var containersArray = new Array();
var tablesHTMLArray = new Array();

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    if  (request.greeting == "turn on spreadsheet downloader"){
      console.log("runtime.onMessage.turnon");
      addContainersToTables();
      addEventListenersToContainers();
      sendResponse({farewell: "byebye"});
      return true;
    } else {}
    if (request.greeting == "turn off spreadsheet downloader"){
      console.log("else");
      removeEventListenersFromContainers();
      removeContainersFromTables();
      sendResponse({farewell: "byebye"});
      return true;
    } else {}
});

function addContainersToTables(){
      console.log("addContainersToTables");
    var numberOfTables = tablesArray.length;
    for (i = 0; i < numberOfTables; i++) {
      var thisTable = tablesArray[i];
      tablesHTMLArray[i] = thisTable.outerHTML;
      addContainerToOneTable(thisTable);
    }
}

function addContainerToOneTable(thisTable){
      console.log("addContainerToOneTable");
    var thisTableOuterHTML = thisTable.outerHTML;
    thisTable.outerHTML = '<div class="myTableDownloaderContainer">' + thisTableOuterHTML + '<div class="myTableDownloaderOverlay"><img src="chrome-extension://gcecjnpjjcknlgikoofhjoejegiffpdf/icon128.png" class="tableDownloaderIcon"></img></div></div>';
}

function addEventListenersToContainers(){<commit_msg>add detection of whether the page is ready to download tables<commit_after>var tablesArray = document.getElementsByTagName("table");
var containersArray = new Array();
var tablesHTMLArray = new Array();

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    var isThePageSetUpForDownloading = document.getElementsByClassName("myTableDownloaderContainer").length;  // the value of this will be 0 if the page isn't set up
    if  (isThePageSetUpForDownloading == 0){
      console.log("runtime.onMessage.turnon");
      addContainersToTables();
      addEventListenersToContainers();
      sendResponse({farewell: "byebye"});
      return true;
    } else {
      console.log("else");
      removeEventListenersFromContainers();
      removeContainersFromTables();
      sendResponse({farewell: "byebye"});
      return true;
    }
});

function addContainersToTables(){
      console.log("addContainersToTables");
    var numberOfTables = tablesArray.length;
    for (i = 0; i < numberOfTables; i++) {
      var thisTable = tablesArray[i];
      tablesHTMLArray[i] = thisTable.outerHTML;
      addContainerToOneTable(thisTable);
    }
}

function addContainerToOneTable(thisTable){
      console.log("addContainerToOneTable");
    var thisTableOuterHTML = thisTable.outerHTML;
    thisTable.outerHTML = '<div class="myTableDownloaderContainer">' + thisTableOuterHTML + '<div class="myTableDownloaderOverlay"><img src="chrome-extension://gcecjnpjjcknlgikoofhjoejegiffpdf/icon128.png" class="tableDownloaderIcon"></img></div></div>';
}

function addEventListenersToContainers(){
{'fraction_non_alphanumeric': 0.12128072445019406, 'fraction_numerical': 0.003234152652005175, 'mean_word_length': 4.792134831460674, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3538946', 'n_tokens_mistral': 898, 'n_tokens_neox': 884, 'n_words': 169}