<commit_before>class FatTweet {
    constructor(){
        this.processTweetBoxes();
    }
    processTweetBoxes(){
        var FT = this;
        var $tweetBoxes = $('.tweet-box[name="tweet"]:not(.fat-tweet-processed)');
        if(!$tweetBoxes.length) return;
        $tweetBoxes
            .addClass('fat-tweet-processed')
            .each(function(){
                var $tweetBox = $(this);
                var $form = $tweetBox.closest('form');
                FT.processTweetForm($form);
        });
    }
    processTweetForm($form){
        var $button = $('<button class="btn fat-tweet-convert-text js-tooltip" data-delay="150" data-original-title="Convert text into image" type="button"><img src="'+chrome.runtime.getURL('img/32.png')+'"></button>');
        $form
            .addClass('fat-tweet-processed-form')
            .find('.btn.tweet-btn')
            .before($button);
        return $form;
    }
    isTweetFormProcessed($form){
        return $form.hasClass('fat-tweet-processed-form');
    }
    convertText($form){
        var FT = this;
        var $area = $form.find('.tweet-box[name="tweet"]');
        $area.addClass('screenshot-process');
        html2canvas($area.get(0), {
            onrendered: function(canvas) {
                $area.after(canvas);
                $area
                    .removeClass('screenshot-process')
                    .html(FT.getLinksClean($area.children('div')));
                $area.focus();
            }
        });
    }
    getLinksClean($content){
        var $links = $content.find('a');
        var $newContent = $('<div></div>');
        var contentLength = 0;
        $links.each(function(){
            var linkTextLength = $(this).text().toString().length;
            if(contentLength + linkTextLength > 140){
                return false;
            }
            contentLength = contentLength + linkTextLength;
            $newContent.append($(this)).append(' ');
        });
        return $newContent;
    }
}
<commit_msg>Add event listener for convert button click<commit_after>class FatTweet {
    constructor(){
        this.processTweetBoxes();
        var FT = this;
        $('body').on('click', '.fat-tweet-convert-text', function(e){
            e.preventDefault();
            var $form = $(this).closest('form');
            FT.convertText($form);
        });
    }
    processTweetBoxes(){
        var FT = this;
        var $tweetBoxes = $('.tweet-box[name="tweet"]:not(.fat-tweet-processed)');
        if(!$tweetBoxes.length) return;
        $tweetBoxes
            .addClass('fat-tweet-processed')
            .each(function(){
                var $tweetBox = $(this);
                var $form = $tweetBox.closest('form');
                FT.processTweetForm($form);
        });
    }
    processTweetForm($form){
        var $button = $('<button class="btn fat-tweet-convert-text js-tooltip" data-delay="150" data-original-title="Convert text into image" type="button"><img src="'+chrome.runtime.getURL('img/32.png')+'"></button>');
        $form
            .addClass('fat-tweet-processed-form')
            .find('.btn.tweet-btn')
            .before($button);
        return $form;
    }
    isTweetFormProcessed($form){
        return $form.hasClass('fat-tweet-processed-form');
    }
    convertText($form){
        var FT = this;
        var $area = $form.find('.tweet-box[name="tweet"]');
        $area.addClass('screenshot-process');
        html2canvas($area.get(0), {
            onrendered: function(canvas) {
                $area.after(canvas);
                $area
                    .removeClass('screenshot-process')
                    .html(FT.getLinksClean($area.children('div')));
                $area.focus();
            }
        });
    }
    getLinksClean($content){
        var $links = $content.find('a');
        var $newContent = $('<div></div>');
        var contentLength = 0;
        $links.each(function(){
            var linkTextLength = $(this).text().toString().length;
            if(contentLength + linkTextLength > 140){
                return false;
            }
            contentLength = contentLength + linkTextLength;
            $newContent.append($(this)).append(' ');
        });
        return $newContent;
    }
}

{'fraction_non_alphanumeric': 0.16304093567251463, 'fraction_numerical': 0.005146198830409357, 'mean_word_length': 1.9147920927062032, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3177301', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1226, 'n_words': 191}