<commit_before>jQuery(function ($) {
    var _token = $('meta[name="csrf-token"]').attr('content');
    var puralize = function (count, text) {
        return count + " " + text + ((count === 1) ? "" : "s");
    };
    var doVote = function (e, hash, vote, target) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/n/" + hash + "/vote",
            data: {
                vote: vote,
                _token: _token
            },
            success: function (data, textStatus, xhr) {
                if (xhr.status === 201) {
                    var count = parseInt(target.innerHTML, 10);
                    count += 1;
                    target.innerHTML = puralize(count, data.vote)
                }
                else if(xhr.status === 200) {
                    var other = $(target).siblings('.btn-vote')[0];
                    var count = parseInt(target.innerHTML, 10);
                    var otherCount = parseInt(other.innerHTML, 10);
                    count += 1;
                    otherCount -= 1;
                    otherCount = Math.min(0, Math.abs(otherCount));
                    if (vote === 1) {
                        target.innerHTML = puralize(count, data.vote);
                        other.innerHTML = puralize(otherCount, "Shrug")
                    } else {
                        target.innerHTML = puralize(count, data.vote);
                        other.innerHTML = puralize(otherCount, "Hug")
                    }
                }
            }
        })
    };
    $(".btn-vote").click(function (ev) {
        ev.preventDefault();
        ev.stopPropagation();
        $this = $(this);
        if (!$this.hasClass("active")) {
            $this.addClass("active").siblings().removeClass("active");
            doVote(ev, $this.data("hash"), $this.data("v"), this);
        }
    });
});<commit_msg>fix vote math<commit_after>jQuery(function ($) {
    var _token = $('meta[name="csrf-token"]').attr('content');
    var puralize = function (count, text) {
        return count + " " + text + ((count === 1) ? "" : "s");
    };
    var doVote = function (e, hash, vote, target) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/n/" + hash + "/vote",
            data: {
                vote: vote,
                _token: _token
            },
            success: function (data, textStatus, xhr) {
                if (xhr.status === 201) {
                    var count = parseInt(target.innerHTML, 10);
                    count += 1;
                    target.innerHTML = puralize(count, data.vote)
                }
                else if(xhr.status === 200) {
                    var other = $(target).siblings('.btn-vote')[0];
                    var count = parseInt(target.innerHTML, 10);
                    var otherCount = parseInt(other.innerHTML, 10);
                    count += 1;
                    otherCount -= 1;
                    otherCount = Math.max(0, otherCount);
                    if (vote === 1) {
                        target.innerHTML = puralize(count, data.vote);
                        other.innerHTML = puralize(otherCount, "Shrug")
                    } else {
                        target.innerHTML = puralize(count, data.vote);
                        other.innerHTML = puralize(otherCount, "Hug")
                    }
                }
            }
        })
    };
    $(".btn-vote").click(function (ev) {
        ev.preventDefault();
        ev.stopPropagation();
        $this = $(this);
        if (!$this.hasClass("active")) {
            $this.addClass("active").siblings().removeClass("active");
            doVote(ev, $this.data("hash"), $this.data("v"), this);
        }
    });
});
{'fraction_non_alphanumeric': 0.14992067689053412, 'fraction_numerical': 0.010047593865679535, 'mean_word_length': 1.289951573849879, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4693634', 'n_tokens_mistral': 1065, 'n_tokens_neox': 996, 'n_words': 208}