<commit_before>'use strict';

var xhr = require('../shared/xhr');
var throttle = require('../shared/throttler');

// For documentation purpose
var STATUS_OK = 0;
var STATUS_NO_RESULT = 1;
var STATUS_TOO_MANY_RESULTS = 2;
var STATUS_ERROR = -1;

var renderers = {
    0: renderResults,
    1: renderNoResult,
    2: renderTooManyResults
};
renderers[-1] = renderError;

function search(str) {
    return xhr('/api/search/' + str).then(function(response) {
        hideAlerts();
        return renderers[response.status](response.results);
    });
}

var searchInput = document.querySelector('#search');

searchInput.addEventListener('input', function() {
    window.history.pushState({}, '', '?' + this.value);
    window.onpopstate();
});


window.onpopstate = throttle(300, function() {
    if (searchInput.value === '') {
        clearResults();
        return;
    }
    search(window.location.search.slice(1));
});

if (window.location.search.length > 1) {
    search(window.location.search.slice(1));
    searchInput.value = window.location.search.slice(1);
}

var resultsTable = document.querySelector('#results');

function clearResults() {
    var trs = resultsTable.querySelectorAll('tbody > tr');
    for (var i = 0; i < trs.length; i++) {
        trs[i].remove();
    }
}

function renderResults(results) {
    clearResults();

    var tbody = resultsTable.querySelector('tbody');
    var newTr;
    for (var i = 0; i < results.length; i++) {<commit_msg>Hide alerts at the proper time.<commit_after>'use strict';

var xhr = require('../shared/xhr');
var throttle = require('../shared/throttler');

// For documentation purpose
var STATUS_OK = 0;
var STATUS_NO_RESULT = 1;
var STATUS_TOO_MANY_RESULTS = 2;
var STATUS_ERROR = -1;

var renderers = {
    0: renderResults,
    1: renderNoResult,
    2: renderTooManyResults
};
renderers[-1] = renderError;

function search(str) {
    return xhr('/api/search/' + str).then(function(response) {
        return renderers[response.status](response.results);
    });
}

var searchInput = document.querySelector('#search');

searchInput.addEventListener('input', function() {
    window.history.pushState({}, '', '?' + this.value);
    window.onpopstate();
});


window.onpopstate = throttle(300, function() {
    if (searchInput.value === '') {
        clearResults();
        return;
    }
    search(window.location.search.slice(1));
});

if (window.location.search.length > 1) {
    search(window.location.search.slice(1));
    searchInput.value = window.location.search.slice(1);
}

var resultsTable = document.querySelector('#results');

function clearResults() {
    var trs = resultsTable.querySelectorAll('tbody > tr');
    for (var i = 0; i < trs.length; i++) {
        trs[i].remove();
    }
    hideAlerts();
}

function renderResults(results) {
    clearResults();

    var tbody = resultsTable.querySelector('tbody');
    var newTr;
    for (var i = 0; i < results.length; i++) {
{'fraction_non_alphanumeric': 0.16134510869565216, 'fraction_numerical': 0.01154891304347826, 'mean_word_length': 3.6524486571879935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5967633', 'n_tokens_mistral': 951, 'n_tokens_neox': 931, 'n_words': 195}