<commit_before>window.onload = function() {

    var socket = io();
    var init = false;
    var spinnerEl = document.querySelector('.spinner__container');
    var loginWrapperEl = document.querySelector('.login-wrapper');
    var loginFormEl = document.querySelector('.login');
    var loginInputEl = document.querySelector('.login-input');
    var usernameInvalidEl = document.querySelector('.username-invalid');
    var usernameTakenEl = document.querySelector('.username-taken');
    var usersOnlineEl = document.querySelector('.users-online');
    var userNumEl = document.querySelectorAll('.user-no');
    var chatBoxEl = document.querySelector('.chatbox');
    var messageFormEl = document.querySelector('.send-msg form');
    var messageInputEl = document.querySelector('.msg');
    var openSideBarEl = document.querySelector('.pull');
    var closeSideBarEl = document.querySelector('.close');
    var username;
    var users;
    var isTyping = false;
    var lastTimeout;

    loginFormEl.addEventListener('submit', onLogin);
    messageFormEl.addEventListener('submit', onMessage);
    openSideBarEl.addEventListener('click', toggleSideBar);
    closeSideBarEl.addEventListener('click', toggleSideBar);
    messageInputEl.onkeydown = onTyping;

    socket.on('init', onInit);
    socket.on('joined', postNotice);
    socket.on('disconnect', postNotice);
    socket.on('chat message', postMessage);
    socket.on('started typing', onStartedTyping);
    socket.on('ended typing', onEndedTyping);

    function onLogin(evt) {
        evt.preventDefault();
        if (!init) return;
        username = loginInputEl.value.trim();
        if (!validateUsername())
            return;

        users.push(username);
        socket.emit('login', username);

        updateUserNum(users.length);
        var meEl = document.querySelector('.me');
        meEl.appendChild(document.createTextNode(username));
        meEl.style.display = 'block';

        loginWrapperEl.addEventListener('transitionend', function(evt) {
            loginWrapperEl.parentNode.removeChild(loginWrapperEl);
            loginWrapperEl.removeEventListener('transitionend', this);
        });
        loginWrapperEl.classList.add('login-wrapper--disabled');

        loginFormEl.removeEventListener('submit', onLogin);
    }

    function validateUsername() {
        if (!/^[a-z0-9_-]{3,15}$/i.test(username)) {
            if (usernameTakenEl.style.display === 'block')
                usernameTakenEl.style.display = 'none';
            if (usernameInvalidEl.style.display === 'none' || !usernameInvalidEl.style.display)
                usernameInvalidEl.style.display = 'block';
            return false;
        }
        if (usernameInvalidEl.style.display === 'block')
                usernameInvalidEl.style.display = 'none';
        var usernameTaken = false;
        for (var i = 0; i < users.length; i++) {
            if (users[i] === username) {
                usernameTaken = true;
                break;
            }
        }
        if (usernameTaken) {
            if (usernameTakenEl.style.display === 'none' || !usernameTakenEl.style.display)
                usernameTakenEl.style.display = 'block';
            return false;
        }
        if (usernameTakenEl.style.display === 'block')
            usernameTakenEl.style.display = 'none';
        return true;
    }

    function onInit(existingUsers) {
        init = true;
        users = existingUsers;
        updateUserNum(users.length);
        users.forEach(function(user) {
            var newUserListEl = document.createElement('div');
            newUserListEl.setAttribute('data-user', user);
            var newUsername = document.createTextNode(user);
            newUserListEl.appendChild(newUsername);
            usersOnlineEl.appendChild(newUserListEl);
        });
        spinnerEl.addEventListener('transitionend', function(evt) {
            spinnerEl.parentNode.removeChild(spinnerEl);
            spinnerEl.removeEventListener('transitionend', this);
        });
        spinnerEl.classList.add('spinner__container--disabled');
    }

    function onTyping(evt) {
        if (!isTyping) {
            isTyping = true;
            socket.emit('started typing', username);
        }
        if (lastTimeout)
            clearTimeout(lastTimeout);
        lastTimeout = setTimeout(function() {
            isTyping = false;
            socket.emit('ended typing', username);
        }, 2000);
    }

    function onStartedTyping(user) {
        var newBubbleEl = document.createElement('div');
        newBubbleEl.classList.add('bubble');
        newBubbleEl.classList.add('typing-indicator');
        newBubbleEl.innerHTML = '<span></span><span></span><span></span>';
        var lastMessageEl = chatBoxEl.querySelectorAll('li');
        lastMessageEl = lastMessageEl[lastMessageEl.length - 1];
        if (lastMessageEl && lastMessageEl.getAttribute('data-user') === user) {
            lastMessageEl.appendChild(newBubbleEl);
            return;
        }<commit_msg>Typing notification bug fix<commit_after>window.onload = function() {

    var socket = io();
    var init = false;
    var spinnerEl = document.querySelector('.spinner__container');
    var loginWrapperEl = document.querySelector('.login-wrapper');
    var loginFormEl = document.querySelector('.login');
    var loginInputEl = document.querySelector('.login-input');
    var usernameInvalidEl = document.querySelector('.username-invalid');
    var usernameTakenEl = document.querySelector('.username-taken');
    var usersOnlineEl = document.querySelector('.users-online');
    var userNumEl = document.querySelectorAll('.user-no');
    var chatBoxEl = document.querySelector('.chatbox');
    var messageFormEl = document.querySelector('.send-msg form');
    var messageInputEl = document.querySelector('.msg');
    var openSideBarEl = document.querySelector('.pull');
    var closeSideBarEl = document.querySelector('.close');
    var username;
    var users;
    var isTyping = false;
    var lastTimeout;

    loginFormEl.addEventListener('submit', onLogin);
    messageFormEl.addEventListener('submit', onMessage);
    openSideBarEl.addEventListener('click', toggleSideBar);
    closeSideBarEl.addEventListener('click', toggleSideBar);
    messageInputEl.onkeydown = onTyping;

    socket.on('init', onInit);
    socket.on('joined', postNotice);
    socket.on('disconnect', postNotice);
    socket.on('chat message', postMessage);
    socket.on('started typing', onStartedTyping);
    socket.on('ended typing', onEndedTyping);

    function onLogin(evt) {
        evt.preventDefault();
        if (!init) return;
        username = loginInputEl.value.trim();
        if (!validateUsername())
            return;

        users.push(username);
        socket.emit('login', username);

        updateUserNum(users.length);
        var meEl = document.querySelector('.me');
        meEl.appendChild(document.createTextNode(username));
        meEl.style.display = 'block';

        loginWrapperEl.addEventListener('transitionend', function(evt) {
            loginWrapperEl.parentNode.removeChild(loginWrapperEl);
            loginWrapperEl.removeEventListener('transitionend', this);
        });
        loginWrapperEl.classList.add('login-wrapper--disabled');

        loginFormEl.removeEventListener('submit', onLogin);
    }

    function validateUsername() {
        if (!/^[a-z0-9_-]{3,15}$/i.test(username)) {
            if (usernameTakenEl.style.display === 'block')
                usernameTakenEl.style.display = 'none';
            if (usernameInvalidEl.style.display === 'none' || !usernameInvalidEl.style.display)
                usernameInvalidEl.style.display = 'block';
            return false;
        }
        if (usernameInvalidEl.style.display === 'block')
                usernameInvalidEl.style.display = 'none';
        var usernameTaken = false;
        for (var i = 0; i < users.length; i++) {
            if (users[i] === username) {
                usernameTaken = true;
                break;
            }
        }
        if (usernameTaken) {
            if (usernameTakenEl.style.display === 'none' || !usernameTakenEl.style.display)
                usernameTakenEl.style.display = 'block';
            return false;
        }
        if (usernameTakenEl.style.display === 'block')
            usernameTakenEl.style.display = 'none';
        return true;
    }

    function onInit(existingUsers) {
        init = true;
        users = existingUsers;
        updateUserNum(users.length);
        users.forEach(function(user) {
            var newUserListEl = document.createElement('div');
            newUserListEl.setAttribute('data-user', user);
            var newUsername = document.createTextNode(user);
            newUserListEl.appendChild(newUsername);
            usersOnlineEl.appendChild(newUserListEl);
        });
        spinnerEl.addEventListener('transitionend', function(evt) {
            spinnerEl.parentNode.removeChild(spinnerEl);
            spinnerEl.removeEventListener('transitionend', this);
        });
        spinnerEl.classList.add('spinner__container--disabled');
    }

    function onTyping(evt) {
        if (!messageInputEl.value) return;
        if (!isTyping) {
            isTyping = true;
            socket.emit('started typing', username);
        }
        if (lastTimeout)
            clearTimeout(lastTimeout);
        lastTimeout = setTimeout(function() {
            isTyping = false;
            socket.emit('ended typing', username);
        }, 2000);
    }

    function onStartedTyping(user) {
        var newBubbleEl = document.createElement('div');
        newBubbleEl.classList.add('bubble');
        newBubbleEl.classList.add('typing-indicator');
        newBubbleEl.innerHTML = '<span></span><span></span><span></span>';
        var lastMessageEl = chatBoxEl.querySelectorAll('li');
        lastMessageEl = lastMessageEl[lastMessageEl.length - 1];
        if (lastMessageEl && lastMessageEl.getAttribute('data-user') === user) {
            lastMessageEl.appendChild(newBubbleEl);
            return;
        }
{'fraction_non_alphanumeric': 0.12717958821790956, 'fraction_numerical': 0.002167274160181263, 'mean_word_length': 2.688953488372093, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '606949', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2693, 'n_words': 468}