<commit_before>$( document ).ready(function() {
    $('#datepicker').datepicker();

    // Auto click today after page is loaded
    $('.active').trigger('click');
    $('.active').addClass('diary-selected');

    // Create Diary
    $('#diary-save').click(function() {
        if($("form")[0].checkValidity()) {
            var diaryContent = $('#diary-content').val();
            var diaryDatetime = $('#selected-datetime').val();
            var diaryCreateAPIUrl = "/api/diary/";
            var data = {
                datetime: diaryDatetime,
                content: diaryContent
            };
            $.ajax({
                type: "POST",
                url: diaryCreateAPIUrl,
                data: data,
                success: function(data) {
                    if(data.result) {
                        $('.diary-selected').addClass('diary-written');
                        $('#diary-delete').attr("disabled", false);
                        toastr.success('일기가 저장되었습니다.');
                    }
                    else {
                        toastr.error('한글을 쓰시면 안되요.\n일기를 저장하지 않습니다!');

                    }
                },
                error: function(error) {
                    console.log(error);
                }
            });
            return false;
        }
    });

    // Delete Diary
    $('#diary-delete').click(function() {
        var diaryDatetime = $('#selected-datetime').val();
        var diaryDeleteAPIUrl = "/api/diary/" + diaryDatetime;
        var data = {
            datetime: diaryDatetime,
        };
        if (confirm('정말 일기를 삭제하시겠습니까?')) {
            $.ajax({
                type: "DELETE",
                url: diaryDeleteAPIUrl,
                data: data,
                success: function(data) {
                    $('#diary-content').val("");
                    $('#diary-translated-content').val("");
                    $('.diary-selected').removeClass('diary-written');
                    toastr.warning("일기가 삭제되었습니다.");
                },
                error: function(error) {
                    console.log(error);
                }
            });
        }
        return false;
    });

    // Trigger a button click with JavaScript on the Enter key in a text box
    $("#find-word").keyup(function(event){
        if(event.keyCode == 13){
            $("#dictionary").click();
        }
    });

    // Dictionary
    $('#dictionary').click(function() {
        var findWord = $('#find-word').val();
        var special_pattern = /[`~!@#$%^&*|\\\'\";:\/?]/gi;
        if(findWord) {
            // Check blank and special letters
            if(special_pattern.test(findWord))
                alert("특수문자는 입력할 수 없습니다.");
            else {
                // Blank => "+"
                findWord.replace(" ","+");
                var naverDictionaryAPIUrl = "/api/naver/dict/" + findWord;
                $.ajax({
                    type: "GET",
                    url: naverDictionaryAPIUrl,
                    success: function(data) {
                        $("#modal-searched-word").text(data.searched_word);
                        if(data.word_meaning)
                            $("#modal-word-meaning").text(data.word_meaning);
                        else
                            $("#modal-word-meaning").text("검색결과가 없습니다.");
                        $('#dictionaryModal').modal('show');
                    },
                    error: function(error) {
                        console.log(error);
                    }
                });
            }
        }
        else {
            alert("검색어를 입력하세요");
        }
        return false;
    });

    // Translate
    $('#diary-translate').click(function() {
        if($("form")[0].checkValidity()) {
            var diaryTranslateAPIUrl = "/api/naver/translate/";
            var diaryContentTextareaElement = $("#diary-content");
            var diaryTranslatedContentTextareaElement = $("#diary-translated-content");

            // input 타입의 .val()로 받으세요(.text로 썼기에 에러났었음)
            var data = {
                content: diaryContentTextareaElement.val()
            };

            $.ajax({
                type:"POST",
                data: data,
                url: diaryTranslateAPIUrl,

                // translate.py 의 response 받기
                success: function(data) {
                    var diaryTranslatedContent = data.content;
                    diaryTranslatedContentTextareaElement.val(diaryTranslatedContent);
                },
                error: function(error) {<commit_msg>update home.js: change alert -> toastr.message<commit_after>$( document ).ready(function() {
    $('#datepicker').datepicker();

    // Auto click today after page is loaded
    $('.active').trigger('click');
    $('.active').addClass('diary-selected');

    // Create Diary
    $('#diary-save').click(function() {
        if($("form")[0].checkValidity()) {
            var diaryContent = $('#diary-content').val();
            var diaryDatetime = $('#selected-datetime').val();
            var diaryCreateAPIUrl = "/api/diary/";
            var data = {
                datetime: diaryDatetime,
                content: diaryContent
            };
            $.ajax({
                type: "POST",
                url: diaryCreateAPIUrl,
                data: data,
                success: function(data) {
                    if(data.result) {
                        $('.diary-selected').addClass('diary-written');
                        $('#diary-delete').attr("disabled", false);
                        toastr.success('일기가 저장되었습니다.');
                    }
                    else {
                        toastr.error("한글을 쓰시면 안되요!", "저장 실패");

                    }
                },
                error: function(error) {
                    console.log(error);
                }
            });
            return false;
        }
    });

    // Delete Diary
    $('#diary-delete').click(function() {
        var diaryDatetime = $('#selected-datetime').val();
        var diaryDeleteAPIUrl = "/api/diary/" + diaryDatetime;
        var data = {
            datetime: diaryDatetime,
        };
        if (confirm('정말 일기를 삭제하시겠습니까?')) {
            $.ajax({
                type: "DELETE",
                url: diaryDeleteAPIUrl,
                data: data,
                success: function(data) {
                    $('#diary-content').val("");
                    $('#diary-translated-content').val("");
                    $('.diary-selected').removeClass('diary-written');
                    toastr.warning("일기가 삭제되었습니다.");
                },
                error: function(error) {
                    console.log(error);
                }
            });
        }
        return false;
    });

    // Trigger a button click with JavaScript on the Enter key in a text box
    $("#find-word").keyup(function(event){
        if(event.keyCode == 13){
            $("#dictionary").click();
        }
    });

    // Dictionary
    $('#dictionary').click(function() {
        var findWord = $('#find-word').val();
        var special_pattern = /[`~!@#$%^&*|\\\'\";:\/?]/gi;
        if(findWord) {
            // Check blank and special letters
            if(special_pattern.test(findWord))
                toastr.error("특수문자는 입력할 수 없습니다.");
            else {
                // Blank => "+"
                findWord.replace(" ","+");
                var naverDictionaryAPIUrl = "/api/naver/dict/" + findWord;
                $.ajax({
                    type: "GET",
                    url: naverDictionaryAPIUrl,
                    success: function(data) {
                        $("#modal-searched-word").text(data.searched_word);
                        if(data.word_meaning)
                            $("#modal-word-meaning").text(data.word_meaning);
                        else
                            $("#modal-word-meaning").text("검색결과가 없습니다.");
                        $('#dictionaryModal').modal('show');
                    },
                    error: function(error) {
                        console.log(error);
                    }
                });
            }
        }
        else {
            toastr.error("검색어를 입력하세요");
        }
        return false;
    });

    // Translate
    $('#diary-translate').click(function() {
        if($("form")[0].checkValidity()) {
            var diaryTranslateAPIUrl = "/api/naver/translate/";
            var diaryContentTextareaElement = $("#diary-content");
            var diaryTranslatedContentTextareaElement = $("#diary-translated-content");

            // input 타입의 .val()로 받으세요(.text로 썼기에 에러났었음)
            var data = {
                content: diaryContentTextareaElement.val()
            };

            $.ajax({
                type:"POST",
                data: data,
                url: diaryTranslateAPIUrl,

                // translate.py 의 response 받기
                success: function(data) {
                    var diaryTranslatedContent = data.content;
                    diaryTranslatedContentTextareaElement.val(diaryTranslatedContent);
                },
                error: function(error) {
{'fraction_non_alphanumeric': 0.14397394136807817, 'fraction_numerical': 0.0008686210640608035, 'mean_word_length': 1.2526290046466129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '244109', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2504, 'n_words': 406}