<commit_before>var list = document.getElementsByTagName("ul")[0];
var form = document.forms[0];
var url = "https://vsr.informatik.tu-chemnitz.de/edu/2015/evs/exercises/jsajax/guestbook.php";
var localEntries = {};

function fixedEncodeURIComponent(str) {
    "use strict";
    return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
        return '%' + c.charCodeAt(0).toString(16);
    });
}

function getEntries(array) {
    "use strict";
    var entryCount = array.length;
    var i;
    var entry;
    for (i = 0; i < entryCount; ++i) {
        if (String(array[i].id) in localEntries) {
            continue;
        }
        entry = document.createElement("li");
        entry.innerHTML = "<b>" + array[i].name + ":</b> " + array[i].text
            + " <a href=\"#\" alt=\"Delete entry\">(X)</a>";
        entry.setAttribute("entry-id", array[i].id);
        entry.lastElementChild.addEventListener("click", function () {
            removeEntry(this);
        });
        list.appendChild(entry);
        localEntries[String(array[i].id)] = entry;
    }
    return;
}

function getSingleEntry(object) {
    "use strict";
    if (String(object.id) in localEntries) {
        return;
    }
    entry = document.createElement("li");
    entry.innerHTML = "<b>" + object.name + ":</b> " + object.text
        + " <a href=\"#\" alt=\"Delete entry\">(X)</a>";
    entry.setAttribute("entry-id", object.id);
    entry.lastElementChild.addEventListener("click", function () {
        removeEntry(this);
    });
    list.appendChild(entry);
    localEntries[String(object.id)] = entry;
    return;
}

function removeEntry(aTag) {
    "use strict";
    var id = aTag.parentElement.getAttribute("entry-id");
    var params = "id=" + id
    var xhr = new XMLHttpRequest();
    xhr.open("DELETE", url + "?" + params, true);
    xhr.send();
    list.removeChild(localEntries[id]);
    delete localEntries[id];
    return;
}

function loadList() {
    "use strict";
    var xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            getEntries(JSON.parse(this.responseText));
        }
    };
    xhr.send();
    return;
}

function postEntry() {
    "use strict";
    var xhr = new XMLHttpRequest();
    var name = fixedEncodeURIComponent(form["name"].value);
    var text = fixedEncodeURIComponent(form["text"].value);
    var params = "name=" + name + "&text=" + text;
    var response;
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            response = JSON.parse(this.responseText);
            getSingleEntry(response.entry);
        }<commit_msg>Rename functions<commit_after>var list = document.getElementsByTagName("ul")[0];
var form = document.forms[0];
var url = "https://vsr.informatik.tu-chemnitz.de/edu/2015/evs/exercises/jsajax/guestbook.php";
var localEntries = {};

function fixedEncodeURIComponent(str) {
    "use strict";
    return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
        return '%' + c.charCodeAt(0).toString(16);
    });
}

function showAllEntries(array) {
    "use strict";
    var entryCount = array.length;
    var i;
    var entry;
    for (i = 0; i < entryCount; ++i) {
        if (String(array[i].id) in localEntries) {
            continue;
        }
        entry = document.createElement("li");
        entry.innerHTML = "<b>" + array[i].name + ":</b> " + array[i].text
            + " <a href=\"#\" alt=\"Delete entry\">(X)</a>";
        entry.setAttribute("entry-id", String(array[i].id));
        entry.lastElementChild.addEventListener("click", function () {
            removeEntry(this);
        });
        list.appendChild(entry);
        localEntries[String(array[i].id)] = entry;
    }
    return;
}

function showSingleEntry(id, name, text) {
    "use strict";
    if (String(id) in localEntries) {
        return;
    }
    var entry = document.createElement("li");
    entry.innerHTML = "<b>" + name + ":</b> " + text
        + " <a href=\"#\" alt=\"Delete entry\">(X)</a>";
    entry.setAttribute("entry-id", String(id));
    entry.lastElementChild.addEventListener("click", function () {
        removeEntry(this);
    });
    list.appendChild(entry);
    localEntries[String(id)] = entry;
    return;
}

function removeEntry(aTag) {
    "use strict";
    var id = aTag.parentElement.getAttribute("entry-id");
    var params = "id=" + id
    var xhr = new XMLHttpRequest();
    xhr.open("DELETE", url + "?" + params, true);
    xhr.send();
    list.removeChild(localEntries[id]);
    delete localEntries[id];
    return;
}

function loadList() {
    "use strict";
    var xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            showAllEntries(JSON.parse(this.responseText));
        }
    };
    xhr.send();
    return;
}

function postEntry() {
    "use strict";
    var xhr = new XMLHttpRequest();
    var name = fixedEncodeURIComponent(form["name"].value);
    var text = fixedEncodeURIComponent(form["text"].value);
    var params = "name=" + name + "&text=" + text;
    var response;
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var r = JSON.parse(this.responseText);
            showSingleEntry(r.entry.id, r.entry.name, r.entry.text);
        }
{'fraction_non_alphanumeric': 0.1726012980178916, 'fraction_numerical': 0.006314681634800912, 'mean_word_length': 2.82171581769437, 'pattern_counts': {'":': 4, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4176147', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1831, 'n_words': 355}