<commit_before>$(function () {

    function getLang() {
        return $('.lang-select option:selected').text();
    }

    function initSelect() {
        $('select').material_select();
    }

    function setupLanguages(langs) {
        $('.lang-select').html('');
        langs.forEach(function (lang, index) {
            $('.lang-select').append('<option value="' + lang + '">' + lang + '</option>');
        });
    }

    function setupTopics() {
        var topics = window.lcl.topics,
            topicSelect = $('.topic-select');
        for (topic in topics) {
            topicSelect.append('<option value="' + topic + '">' + topic + '</option>');
        }
    }

    function getInterestWords() {
        var selectedTopic = $('.topic-select option:selected').val();
        return window.lcl.topics[selectedTopic];
    }

    function getGrammar() {
        var interestWords = getInterestWords();
        return '#JSGF V1.0; grammar interest_words; public <interest_words> = ' + interestWords.join(' | ') + ' ;';
    }

    function setupTwoWords($twoWordModeEl, criticalWord1, criticalWord2) {
        $twoWordModeEl.on('change', function (e) {
            if ($(this).prop("checked") == true) {
                criticalWord1.removeClass('s12');
                criticalWord2.removeClass('hide');
            } else {
                criticalWord1.addClass('s12');
                criticalWord2.addClass('hide');
            }
        });
    }

    function init() {
        var started = false,
            reset = false;
        var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
        var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
        var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent;
        var criticalWord1 = $('.critical-word-1');
        var criticalWord2 = $('.critical-word-2');
        var wordContainer = $('.word-container');
        var $twoWordModeEl = $("#two-word-mode");

        var languages_supported = ['en-US', 'en-GB', 'en-IN', 'en-CA', 'en-AU', 'en-NZ', 'en-ZA'];


        var recognition = new SpeechRecognition();
        var speechRecognitionList = new SpeechGrammarList();

        var word1 = "";

        recognition.continuous = true;
        recognition.interimResults = true;
        recognition.maxAlternatives = 2;

        recognition.onresult = function (event) {
            var last = event.results.length - 1;
            var lastSentence = event.results[last][0].transcript;
            var mode = $twoWordModeEl.prop("checked");
            getInterestWords().forEach(function (element, index) {
                if (lastSentence.indexOf(element) != -1) {
                    if (criticalWord1.text() == '') {
                        criticalWord1.text(element);
                        word1 = element;
                    } else if (mode && criticalWord2.text() == '' && element !== word1) {
                        criticalWord2.text(element);
                    }
                }
            });
            if (event.results[last].isFinal) {
                reset = false;
            }
        };

        $(window).keyup(function (evt) {
            evt = evt || window.event;
            var space = '32';
            if (evt.keyCode == space) {
                criticalWord1.text('');
                criticalWord2.text('');
                reset = true;
            }
        });

        $('#start-btn').on('click', function (e) {
            recognition.lang = getLang();
            var grammar = getGrammar();
            speechRecognitionList.addFromString(grammar, 1);
            recognition.grammars = speechRecognitionList;
            if (started) {
                started = false;
                recognition.stop();
                $(this).find('.text').text("Start");
            } else {
                started = true;
                recognition.start();
                $(this).find('.text').text("Stop");
            }
            $(this).blur();
            $(window).focus();
        });<commit_msg>Spiked with saving analytics data. Will refactor this soon<commit_after>$(function () {

    function getLang() {
        return $('.lang-select option:selected').text();
    }

    function initSelect() {
        $('select').material_select();
    }

    function setupLanguages(langs) {
        $('.lang-select').html('');
        langs.forEach(function (lang, index) {
            $('.lang-select').append('<option value="' + lang + '">' + lang + '</option>');
        });
    }

    function setupTopics() {
        var topics = window.lcl.topics,
            topicSelect = $('.topic-select');
        for (topic in topics) {
            topicSelect.append('<option value="' + topic + '">' + topic + '</option>');
        }
    }

    function getInterestWords() {
        var selectedTopic = $('.topic-select option:selected').val();
        return window.lcl.topics[selectedTopic];
    }

    function getGrammar() {
        var interestWords = getInterestWords();
        return '#JSGF V1.0; grammar interest_words; public <interest_words> = ' + interestWords.join(' | ') + ' ;';
    }

    function setupTwoWords($twoWordModeEl, criticalWord1, criticalWord2) {
        $twoWordModeEl.on('change', function (e) {
            if ($(this).prop("checked") == true) {
                criticalWord1.removeClass('s12');
                criticalWord2.removeClass('hide');
            } else {
                criticalWord1.addClass('s12');
                criticalWord2.addClass('hide');
            }
        });
    }

    function init() {
        var started = false,
            reset = true;
        var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
        var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
        var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent;
        var criticalWord1 = $('.critical-word-1');
        var criticalWord2 = $('.critical-word-2');
        var wordContainer = $('.word-container');
        var $twoWordModeEl = $("#two-word-mode");

        var analytics = [];

        var languages_supported = ['en-US', 'en-GB', 'en-IN', 'en-CA', 'en-AU', 'en-NZ', 'en-ZA'];


        var recognition = new SpeechRecognition();
        var speechRecognitionList = new SpeechGrammarList();

        var word1 = "";

        recognition.continuous = true;
        recognition.interimResults = true;
        recognition.maxAlternatives = 1;
        var dataItem = {};
        var identified = false;
        recognition.onresult = function (event) {
            var last = event.results.length - 1;
            var lastSentence = event.results[last][0].transcript;
            var mode = $twoWordModeEl.prop("checked");
            getInterestWords().forEach(function (element, index) {
                if (lastSentence.indexOf(element) != -1 && reset) {
                    if (criticalWord1.text() == '') {
                        criticalWord1.text(element);
                        word1 = element;
                        dataItem.word1 = word1;
                        identified = true;
                    } else if (mode && criticalWord2.text() == '' && element !== word1) {
                        criticalWord2.text(element);
                        dataItem.word2 = element;
                        identified = true;
                    }
                }
            });
            if (event.results[last].isFinal) {
                if (identified) {
                    var sentence = event.results[last][0].transcript;
                    var date = new Date(event.timeStamp);
                    dataItem.sentence = sentence;
                    dataItem.date = date.toGMTString();
                    dataItem.timestamp = event.timeStamp;
                    analytics.push(dataItem);
                    dataItem = {};
                    identified = false;
                }
                reset = false;
            }
        };

        $(window).keyup(function (evt) {
            evt = evt || window.event;
            var space = '32';
            if (evt.keyCode == space) {
                criticalWord1.text('');
                criticalWord2.text('');
                reset = true;
            }
        });

        $('#start-btn').on('click', function (e) {
            recognition.lang = getLang();
            var grammar = getGrammar();
            speechRecognitionList.addFromString(grammar, 1);
            recognition.grammars = speechRecognitionList;
            if (started) {
                started = false;
                console.log(analytics);
                recognition.stop();
                $(this).find('.text').text("Start");
            } else {
                started = true;
                recognition.start();
                $(this).find('.text').text("Stop");
            }
            $(this).blur();
            $(window).focus();
        });
{'fraction_non_alphanumeric': 0.1391700967849594, 'fraction_numerical': 0.0075648014239626206, 'mean_word_length': 1.680381633870006, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5800770', 'n_tokens_mistral': 2463, 'n_tokens_neox': 2290, 'n_words': 450}