<commit_before>/* Google Inbox plugin
 */

App.plugin('google-inbox', (function () {
    // split full name by last space.
    // TODO share this between plugins.
    var splitFullName = function (fullname) {
        fullname = fullname || '';

        var lastSpaceIndex = fullname.lastIndexOf(' ');
        if (lastSpaceIndex < 1) {
            lastSpaceIndex = fullname.length
        }

        return {
            first_name: fullname.substr(0, lastSpaceIndex),
            last_name: fullname.substr(lastSpaceIndex + 1)
        }
    };

    var getNodes = function (element) {
        var nodes = {};

        // editor container classNames:
        // .n7 for message popup
        // .nG for inline reply
        // only one is rendered at a time.
        // default to popup.
        nodes.mode = 'popup';
        nodes.container = jQuery(element).closest('.n7');

        // detect if in message popup or inline.
        if (nodes.container.length) {
            // popup.
            // to, cc, bcc
            var receivers = [
                {type: 'to', className: '.Fv'},
                {type: 'cc', className: '.fD'},
                {type: 'bcc', className: '.fx'}
            ];

            receivers.forEach(function (receiver) {
                // return the field container node,
                // so we can get different child nodes for read-write.
                nodes[receiver.type] = nodes.container.siblings(receiver.className);
            });

            // subject
            nodes.subject = nodes.container.siblings('.iO').find('input');
        } else {
            // inline reply
            nodes.mode = 'inline';
            nodes.container = jQuery(element).closest('.nG');

            var $receivers = nodes.container.prev('.kX').find('[email]');

            // in inline reply, all receivers are a single-level list.
            // since we no way of knowing which is to/cc/bcc,
            // we naively handle them by index.
            ['to', 'cc', 'bcc'].forEach(function (type, index) {
                if ($receivers.eq(index).length) {
                    return nodes[type] = $receivers.eq(index)
                }
            });

            // normalize the subject as an input
            nodes.subject = jQuery(document.createElement('input'));
            nodes.subject.val(nodes.container.closest('.aY').find('[role="heading"] .eo').text());
        }

        return nodes
    };

    // get all required data from the dom
    var getData = function (params, callback) {
        var vars = {
            from: {},
            to: [],
            cc: [],
            bcc: [],
            subject: ''
        };

        // title = Google Account: User Name (<EMAIL>)
        var $signoutBtn = jQuery('.gb_eb');
        var btnTitle = $signoutBtn.attr('title');
        var name = '';
        var sep = ':';

        if (btnTitle.indexOf(sep) !== -1) {
            var prefix = btnTitle.split(sep)[0] + sep;
            name = btnTitle.replace(prefix, '').trim();
        }

        var email = '';
        var openBracket = name.lastIndexOf('(');
        // in case of no brackets
        if (openBracket === -1) {
            openBracket = name.length
        } else {
            email = name.substr(openBracket).slice(1, -1);
        }

        name = name.substr(0, openBracket).trim();

        // from
        vars.from = jQuery.extend({
            name: name,
            email: email
        }, splitFullName(name));

        var nodes = getNodes(params.element);
        ['to', 'cc', 'bcc'].forEach(function (receiver) {
            if (!nodes[receiver]) {
                return
            }

            var $field = nodes[receiver];
            var name = '';

            // inline sends the [email] node,
            // popup sends the [email] node container.
            if (nodes.mode === 'inline') {
                // inline.
                name = $field.text()
            } else {
                // popup.
                // when a receiver is deleted, the node is still there but display:none.
                $field = $field.find('[email]:visible').eq(0);<commit_msg>Some more checks<commit_after>/* Google Inbox plugin
 */

App.plugin('google-inbox', (function () {
    // split full name by last space.
    // TODO share this between plugins.
    var splitFullName = function (fullname) {
        fullname = fullname || '';

        var lastSpaceIndex = fullname.lastIndexOf(' ');
        if (lastSpaceIndex < 1) {
            lastSpaceIndex = fullname.length
        }

        return {
            first_name: fullname.substr(0, lastSpaceIndex),
            last_name: fullname.substr(lastSpaceIndex + 1)
        }
    };

    var getNodes = function (element) {
        var nodes = {};

        // editor container classNames:
        // .n7 for message popup
        // .nG for inline reply
        // only one is rendered at a time.
        // default to popup.
        nodes.mode = 'popup';
        nodes.container = jQuery(element).closest('.n7');

        // detect if in message popup or inline.
        if (nodes.container.length) {
            // popup.
            // to, cc, bcc
            var receivers = [
                {type: 'to', className: '.Fv'},
                {type: 'cc', className: '.fD'},
                {type: 'bcc', className: '.fx'}
            ];

            receivers.forEach(function (receiver) {
                // return the field container node,
                // so we can get different child nodes for read-write.
                nodes[receiver.type] = nodes.container.siblings(receiver.className);
            });

            // subject
            nodes.subject = nodes.container.siblings('.iO').find('input');
        } else {
            // inline reply
            nodes.mode = 'inline';
            nodes.container = jQuery(element).closest('.nG');

            var $receivers = nodes.container.prev('.kX').find('[email]');

            // in inline reply, all receivers are a single-level list.
            // since we no way of knowing which is to/cc/bcc,
            // we naively handle them by index.
            ['to', 'cc', 'bcc'].forEach(function (type, index) {
                if ($receivers.eq(index).length) {
                    return nodes[type] = $receivers.eq(index)
                }
            });

            // normalize the subject as an input
            nodes.subject = jQuery(document.createElement('input'));
            nodes.subject.val(nodes.container.closest('.aY').find('[role="heading"] .eo').text());
        }

        return nodes
    };

    // get all required data from the dom
    var getData = function (params, callback) {
        var vars = {
            from: {},
            to: [],
            cc: [],
            bcc: [],
            subject: ''
        };

        // title = Google Account: User Name (<EMAIL>)
        var $signoutBtn = jQuery('.gb_eb');
        var btnTitle = $signoutBtn.attr('title');
        var name = '';
        var sep = ':';

        if (btnTitle && btnTitle.indexOf(sep) !== -1) {
            var prefix = btnTitle.split(sep)[0] + sep;
            name = btnTitle.replace(prefix, '').trim();
        }

        var email = '';

        if (name) {
            var openBracket = name.lastIndexOf('(');
            // in case of no brackets
            if (openBracket === -1) {
                openBracket = name.length
            } else {
                email = name.substr(openBracket).slice(1, -1);
            }

            name = name.substr(0, openBracket).trim();
        }

        // from
        vars.from = jQuery.extend({
            name: name,
            email: email
        }, splitFullName(name));

        var nodes = getNodes(params.element);
        ['to', 'cc', 'bcc'].forEach(function (receiver) {
            if (!nodes[receiver]) {
                return
            }

            var $field = nodes[receiver];
            var name = '';

            // inline sends the [email] node,
            // popup sends the [email] node container.
            if (nodes.mode === 'inline') {
                // inline.
                name = $field.text()
            } else {
                // popup.
                // when a receiver is deleted, the node is still there but display:none.
                $field = $field.find('[email]:visible').eq(0);
{'fraction_non_alphanumeric': 0.13465204957102003, 'fraction_numerical': 0.002859866539561487, 'mean_word_length': 1.4512266355140186, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5885639', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2209, 'n_words': 596}