<commit_before>var priorLocation;

function logInit() {
  localStorage.setItem('test-log', '');
}

function logPhase() {
  var log = localStorage.getItem('test-log') || '';
  log += '\n' + Array.prototype.slice.call(arguments).join(' ') + '\n';
  localStorage.setItem('test-log', log);
}
function logStep() {
  var log = localStorage.getItem('test-log') || '';

  if (priorLocation != window.location) {
    priorLocation = window.location + '';
    if (arguments[0] !== 'location-change') {
      log += '  location-change ' + priorLocation + '\n';
    }
  }

  log += '  ' + Array.prototype.slice.call(arguments).join(' ') + '\n';

  localStorage.setItem('test-log', log);
}

function logFlush() {
  console.log(localStorage.getItem('test-log'));
  localStorage.removeItem('test-log');
}


function eventListeners() {
  if (testOptions.all || testOptions.beforeunload) {
    window.addEventListener('beforeunload', function() {
      logStep('beforeunload');
    });
  }

  if (testOptions.all || testOptions.pagehide) {
    window.addEventListener('pagehide', function() {
      logStep('pagehide');
    });
  }

  if (testOptions.all || testOptions.unload) {
    window.addEventListener('unload', function() {
      logStep('unload');
    });
  }

  if (testOptions.all || testOptions.hashchange) {
    // TODO : Is this working?
    window.addEventListener('hashchange', function() {
      logStep('hashchange');
    });
  }

  if (testOptions.all || testOptions.popstate) {
    window.addEventListener('popstate', function() {
      logStep('popstate');
    });
  }

  if (testOptions.all || testOptions.error) {
    window.addEventListener('error', function() {
      logStep('capturing error');
    }, true);
  }
}

if (window.testOptions) {
  eventListeners();
}
logStep('location-change', window.location+'');
<commit_msg>Log results to server<commit_after>var priorLocation;

function logInit() {
  localStorage.setItem('test-log', '');
}

function logPhase() {
  var log = localStorage.getItem('test-log') || '';
  log += '\n' + Array.prototype.slice.call(arguments).join(' ') + '\n';
  localStorage.setItem('test-log', log);
}
function logStep() {
  var log = localStorage.getItem('test-log') || '';

  if (priorLocation != window.location) {
    priorLocation = window.location + '';
    if (arguments[0] !== 'location-change') {
      log += '  location-change ' + priorLocation + '\n';
    }
  }

  log += '  ' + Array.prototype.slice.call(arguments).join(' ') + '\n';

  localStorage.setItem('test-log', log);
}

function logFlush() {
  console.log(localStorage.getItem('test-log'));
  $.ajax({
    url: '/log',
    data: {
      log: localStorage.getItem('test-log')
    }
  });
  localStorage.removeItem('test-log');
}


function eventListeners() {
  if (testOptions.all || testOptions.beforeunload) {
    window.addEventListener('beforeunload', function() {
      logStep('beforeunload');
    });
  }

  if (testOptions.all || testOptions.pagehide) {
    window.addEventListener('pagehide', function() {
      logStep('pagehide');
    });
  }

  if (testOptions.all || testOptions.unload) {
    window.addEventListener('unload', function() {
      logStep('unload');
    });
  }

  if (testOptions.all || testOptions.hashchange) {
    // TODO : Is this working?
    window.addEventListener('hashchange', function() {
      logStep('hashchange');
    });
  }

  if (testOptions.all || testOptions.popstate) {
    window.addEventListener('popstate', function() {
      logStep('popstate');
    });
  }

  if (testOptions.all || testOptions.error) {
    window.addEventListener('error', function() {
      logStep('capturing error');
    }, true);
  }
}

if (window.testOptions) {
  eventListeners();
}
logStep('location-change', window.location+'');

{'fraction_non_alphanumeric': 0.18418259023354563, 'fraction_numerical': 0.0005307855626326964, 'mean_word_length': 3.601953601953602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5908189', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1180, 'n_words': 191}