<commit_before>var ws = new WebSocket("ws://localhost:8888/websocket");

var name = getParameterByName("name") || "guest";
var recentname = null;

ws.onmessage = function (evt) {
    var Mname = evt.data.substr(0,evt.data.indexOf(':'));
    var Mdat = evt.data.substr(evt.data.indexOf(':')+1);
    var element = document.getElementById("chat");

    var article = document.createElement("article");
    article.className = "message"

    if (recentname != Mname) { //only use name if its a different user
        var head = document.createElement("h3");
        var name_node = document.createTextNode(Mname);
        head.appendChild(name_node);
        head.className = "name";
        article.appendChild(head);
        recentname = Mname;
    }

    if (Mdat.indexOf("@"+name) != -1) { //highlight @name mentions
        article.className += " mention"
    }
    article = doMentions(article, Mdat)

    element.appendChild(article);

    window.scrollTo(0,document.body.scrollHeight);
};

function doMentions(element, str){
    str = str.split(" ");
    var para = document.createElement("p");

    for (var i = 0; i < str.length; i++) {
        if (str[i].substring(0,1) == "@") {
            var span = document.createElement("span");
            var node = document.createTextNode(str[i]+" ");

            span.appendChild(node);
            span.className = "color";
            para.appendChild(span);
        } else {
            var node = document.createTextNode(str[i]+" ");
            para.appendChild(node);
        }
    }

    element.appendChild(para);
    return element;
}

function submit() {
    var inp = document.getElementById("inp")
    if (inp.value != "") {
        ws.send(name+":"+inp.value);
        inp.value = ""
    }
}

window.onbeforeunload = function() {
    ws.close()
};

document.onkeypress = function (e) {
    e = e || window.event;
    e = e.which || e.KeyCode
    if (e == 13) {
        submit();
    }
};

function getParameterByName(name, url) { //this is not my code
    if (!url) url = window.location.href;
    url = url.toLowerCase(); // This is just to avoid case sensitiveness
    name = name.replace(/[\[\]]/g, "\\$&").toLowerCase();// This is just to avoid case sensitiveness for query parameter name
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}<commit_msg>name is now stored in local storage<commit_after>var ws = new WebSocket("ws://localhost:8888/websocket");

var name = localStorage.getItem("name") || "guest";
var recentname = null;

ws.onmessage = function (evt) {
    var Mname = evt.data.substr(0,evt.data.indexOf(':'));
    var Mdat = evt.data.substr(evt.data.indexOf(':')+1);
    var element = document.getElementById("chat");

    var article = document.createElement("article");
    article.className = "message"

    if (recentname != Mname) { //only use name if its a different user
        var head = document.createElement("h3");
        var name_node = document.createTextNode(Mname);
        head.appendChild(name_node);
        head.className = "name";
        article.appendChild(head);
        recentname = Mname;
    }

    if (Mdat.indexOf("@"+name) != -1) { //highlight @name mentions
        article.className += " mention"
    }
    article = doMentions(article, Mdat)

    element.appendChild(article);

    window.scrollTo(0,document.body.scrollHeight);
};

function doMentions(element, str){
    str = str.split(" ");
    var para = document.createElement("p");

    for (var i = 0; i < str.length; i++) {
        if (str[i].substring(0,1) == "@") {
            var span = document.createElement("span");
            var node = document.createTextNode(str[i]+" ");

            span.appendChild(node);
            span.className = "color";
            para.appendChild(span);
        } else {
            var node = document.createTextNode(str[i]+" ");
            para.appendChild(node);
        }
    }

    element.appendChild(para);
    return element;
}

function submit() {
    var inp = document.getElementById("inp")
    if (inp.value != "") {
        ws.send(name+":"+inp.value);
        inp.value = ""
    }
}

window.onbeforeunload = function() {
    ws.close()
};

document.onkeypress = function (e) {
    e = e || window.event;
    e = e.which || e.KeyCode
    if (e == 13) {
        submit();
    }
};
{'fraction_non_alphanumeric': 0.16544035674470456, 'fraction_numerical': 0.006688963210702341, 'mean_word_length': 2.6412337662337664, 'pattern_counts': {'":': 2, '<': 5, '<?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': '6823204', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1387, 'n_words': 305}