<commit_before>///////////////////////////////////////////
// gmail.js
// <NAME>
// https://github.com/KartikTalwar/gmail.js
//

var Gmail_ = function(localJQuery) {

  /*
    Use the provided 'jQuery' if possible, in order to avoid conflicts with
    other extensions that use $ for other purposes.
  */
  var $;
  if (typeof localJQuery !== "undefined") {
    $ = localJQuery;
  } else if (typeof jQuery !== "undefined") {
    $ = jQuery;
  }
  // else leave $ undefined, which may be fine for some purposes.

  var api = {
              get : {},
              observe : {},
              check : {},
              tools : {},
              tracker : {},
              dom : {},
              chat : {},
              compose : {},
              helper : {get: {}}
            };

  api.version           = "0.5";
  api.tracker.globals   = typeof GLOBALS !== 'undefined' ? GLOBALS : ( window.opener != null && typeof window.opener.GLOBALS !== 'undefined' ? window.opener.GLOBALS : [] );
  api.tracker.view_data = typeof VIEW_DATA !== 'undefined' ? VIEW_DATA : ( window.opener != null && typeof window.opener.VIEW_DATA !== 'undefined' ? window.opener.VIEW_DATA : [] );
  api.tracker.ik        = api.tracker.globals[9] || "";
  api.tracker.hangouts  = undefined;


  api.get.last_active = function() {
    var data = api.tracker.globals[17][15];
    return {
             time : data[1],
             ip : data[3],
             mac_address : data[9],
             time_relative : data[10]
           };
  };


  api.get.loggedin_accounts = function() {
    var i, j, data;
    var users = [];

    var globals17 = api.tracker.globals[17];
    for (i in globals17) {
      // at least for the delegated inboxes, the index of the mla is not stable
      // it was observed to be somewhere between 22 and 24, but we should not depend on it
      data = globals17[i];

      if (data[0] === 'mla') {
        for(j in data[1]) {
          users.push({
            name : data[1][j][4],
            email : data[1][j][0],
            index: data[1][j][3]
          });
        }

        return users;
      }
    }

    return users;
  };


  api.get.user_email = function() {
    return api.tracker.globals[10];
  };


  api.get.manager_email = function() {
    if (api.helper.get.is_delegated_inbox()) {
      return api.get.delegated_to_email();
    }

    return api.get.user_email();
  };


  api.get.delegated_to_email = function() {
    if (!api.helper.get.is_delegated_inbox()) {
      return null;
    }

    var i, account;
    var userIndexPrefix = "/u/";
    var pathname = window.location.pathname;
    var delegatedToUserIndex = parseInt(pathname.substring(pathname.indexOf(userIndexPrefix) + userIndexPrefix.length), 10);

    var loggedInAccounts = api.get.loggedin_accounts();
    if (loggedInAccounts && loggedInAccounts.length > 0) {
      for (i in loggedInAccounts) {
        account = loggedInAccounts[i];
        if (account.index === delegatedToUserIndex) {
          return account.email;
        }
      }
    }

    // as a last resort, we query the DOM of the upper right account selection menu
    return $(".gb_rb[href$='" + userIndexPrefix + delegatedToUserIndex + "'] .gb_yb").text().split(" ")[0];
  };


  api.get.localization = function() {
    var isLocale = function(locale) {
      // A locale is a string that begins with 2 letters, lowercase.
      // The 'lowercase' check distinguishes locales from other 2-letter strings like 'US'
      // (the user's location?).
      if (!locale || ((typeof locale) !== 'string') || locale.length < 2) {
        return false;
      }

      var localePrefix = locale.slice(0, 2);
      return localePrefix.toLowerCase() === localePrefix;
    };

    var globals = api.tracker.globals;

    // First candidate.
    var locale = globals[17] && globals[17][8] && globals[17][8][8];
    if (isLocale(locale)) {
      return locale;
    }

    // Second candidate.
    locale = globals[17] && globals[17][9] && globals[17][9][8];
    if (isLocale(locale)) {
      return locale;
    }

    return null;
  };


  api.check.is_thread = function() {
    var check_1 = $('.nH .if').children(":eq(1)").children().children(":eq(1)").children();
    var check_2 = api.get.email_ids();

    return check_1.length > 1 || check_2.length > 1;
  };


  api.dom.inbox_content = function() {
    return $('div[role=main]:first');
  };


  api.check.is_preview_pane = function() {
    var dom = api.dom.inbox_content();
    var boxes = dom.find("[gh=tl]");

    var previewPaneFound = false;
    boxes.each(function() {
      if($(this).hasClass('aia')) {
        previewPaneFound = true;
      }
    });

    return previewPaneFound;
  };

  api.check.is_multiple_inbox = function() {
    var dom = api.dom.inboxes();
    return dom.length > 1;
  };


  api.check.is_horizontal_split = function() {
    var dom = api.dom.inbox_content();
    var box = dom.find("[gh=tl]").find('.nn');

    return box.length == 0;
  };


  api.check.is_vertical_split = function() {
    return api.check.is_horizontal_split() == false;
  };


  api.check.is_tabbed_inbox = function() {
    return $(".aKh").length == 1;
  };


  api.check.is_right_side_chat = function() {
    var chat = $('.ApVoH');
    if(chat.length === 0) {
      return false;
    }

    return chat[0].getAttribute('aria-labelledby') == ':wf';
  }

  api.check.should_compose_fullscreen = function(){
    var bx_scfs = [];
    try {
      bx_scfs = api.tracker.globals[17][4][1][32];
    } catch(er) {
      bx_scfs = ['bx_scfs','false'];
    }
     return (bx_scfs[1] == 'true' ) ? true : false;
  }


  api.check.is_google_apps_user =function() {
    var email = api.get.user_email();
    return email.indexOf('gmail.com', email.length - 'gmail.com'.length) == -1;
  };


  api.get.storage_info = function() {
    var div = $('.md.mj').find('div')[0];
    var used = $(div).find('span')[0].text;
    var total = $(div).find('span')[1].text;
    var percent = parseFloat(used.replace(/[^0-9\.]/g, '')) * 100 / parseFloat(total.replace(/[^0-9\.]/g, ''));

    return {used : used, total : total, percent : Math.floor(percent)}
  };


  api.dom.inboxes = function() {
    var dom = api.dom.inbox_content();
    return dom.find("[gh=tl]");
  };

  api.dom.email_subject = function () {
    var e = $(".hP");

    for(var i=0; i<e.length; i++) {
      if($(e[i]).is(':visible')) {
        return $(e[i]);
      }
    }

    return $();
  };


  api.get.email_subject = function() {
    var subject_dom = api.dom.email_subject();

    return subject_dom.text();
  };


  api.dom.email_body = function() {
    return $('.nH.hx');
  };

  api.dom.toolbar = function() {
    var tb = $("[gh='mtb']");

    while($(tb).children().length == 1){
      tb = $(tb).children().first();
    }

    return tb;
};


  api.check.is_inside_email = function() {
    if(api.get.current_page() != 'email' && !api.check.is_preview_pane()) {
      return false;
    }

    var items = $('.ii.gt .a3s.aXjCH');
    var ids = [];

    for(var i=0; i<items.length; i++) {
      var mail_id = items[i].getAttribute('class').split(' ')[2];
      if(mail_id != 'undefined' && mail_id != undefined) {
        if($(items[i]).is(':visible')) {
          ids.push(items[i]);
        }
      }
    }

    return ids.length > 0;
  };

  api.check.is_plain_text = function() {
    var settings = GLOBALS[17][4][1];

    for (var i = 0; i < settings.length; i++) {
      var plain_text_setting = settings[i];
      if (plain_text_setting[0] === 'bx_cm') {
        return plain_text_setting[1] === '0';
      }
    }

    // default to rich text mode, which is more common nowadays
    return false;
  };

  api.dom.email_contents = function() {
    var items = $('.ii.gt div.a3s.aXjCH');
    var ids = [];

    for(var i=0; i<items.length; i++) {
      var mail_id = items[i].getAttribute('class').split(' ')[2];
      var is_editable = items[i].getAttribute('contenteditable');
      if(mail_id != 'undefined' && mail_id != undefined) {
        if(is_editable != 'true') {
          ids.push(items[i]);
        }
      }
    }

    return ids;
  };


  api.get.email_ids = function() {
    if(api.check.is_inside_email()) {
      var data = api.get.email_data();
      return Object.keys(data.threads);
    }
    return [];
  };


  api.get.compose_ids = function() {
      var ret = [];
      var dom = $(".AD [name=draft]");
      for(var i = 0; i < dom.length; i++) {
          if(dom[i].value != "undefined"){
              ret.push(dom[i].value);
          }
      }
      return ret;
  };


  api.get.email_id = function() {
    var hash = null;

    if(api.check.is_inside_email()) {
      if(api.check.is_preview_pane()) {
        var items = api.dom.email_contents();
        var text = [];

        for(var i=0; i<items.length; i++) {
          var mail_id = items[i].children[0].getAttribute('class').split(' ')[2];
          var is_editable = items[i].getAttribute('contenteditable');
          var is_visible = items[i].offsetWidth > 0 && items[i].offsetHeight > 0;
          if(mail_id != 'undefined' && mail_id != undefined && is_visible) {
            if(is_editable != 'true') {
              text.push(mail_id);
            }
          }
        }

        hash = text[0].substring(1, text[0].length);
      } else {
        hash = window.location.hash.split("/").pop().replace(/#/, '').split('?')[0];
      }
    }<commit_msg>Revert "Fix bug: to get ID of an item with actived Preview pane, we need sear…"<commit_after>///////////////////////////////////////////
// gmail.js
// <NAME>
// https://github.com/KartikTalwar/gmail.js
//

var Gmail_ = function(localJQuery) {

  /*
    Use the provided 'jQuery' if possible, in order to avoid conflicts with
    other extensions that use $ for other purposes.
  */
  var $;
  if (typeof localJQuery !== "undefined") {
    $ = localJQuery;
  } else if (typeof jQuery !== "undefined") {
    $ = jQuery;
  }
  // else leave $ undefined, which may be fine for some purposes.

  var api = {
              get : {},
              observe : {},
              check : {},
              tools : {},
              tracker : {},
              dom : {},
              chat : {},
              compose : {},
              helper : {get: {}}
            };

  api.version           = "0.5";
  api.tracker.globals   = typeof GLOBALS !== 'undefined' ? GLOBALS : ( window.opener != null && typeof window.opener.GLOBALS !== 'undefined' ? window.opener.GLOBALS : [] );
  api.tracker.view_data = typeof VIEW_DATA !== 'undefined' ? VIEW_DATA : ( window.opener != null && typeof window.opener.VIEW_DATA !== 'undefined' ? window.opener.VIEW_DATA : [] );
  api.tracker.ik        = api.tracker.globals[9] || "";
  api.tracker.hangouts  = undefined;


  api.get.last_active = function() {
    var data = api.tracker.globals[17][15];
    return {
             time : data[1],
             ip : data[3],
             mac_address : data[9],
             time_relative : data[10]
           };
  };


  api.get.loggedin_accounts = function() {
    var i, j, data;
    var users = [];

    var globals17 = api.tracker.globals[17];
    for (i in globals17) {
      // at least for the delegated inboxes, the index of the mla is not stable
      // it was observed to be somewhere between 22 and 24, but we should not depend on it
      data = globals17[i];

      if (data[0] === 'mla') {
        for(j in data[1]) {
          users.push({
            name : data[1][j][4],
            email : data[1][j][0],
            index: data[1][j][3]
          });
        }

        return users;
      }
    }

    return users;
  };


  api.get.user_email = function() {
    return api.tracker.globals[10];
  };


  api.get.manager_email = function() {
    if (api.helper.get.is_delegated_inbox()) {
      return api.get.delegated_to_email();
    }

    return api.get.user_email();
  };


  api.get.delegated_to_email = function() {
    if (!api.helper.get.is_delegated_inbox()) {
      return null;
    }

    var i, account;
    var userIndexPrefix = "/u/";
    var pathname = window.location.pathname;
    var delegatedToUserIndex = parseInt(pathname.substring(pathname.indexOf(userIndexPrefix) + userIndexPrefix.length), 10);

    var loggedInAccounts = api.get.loggedin_accounts();
    if (loggedInAccounts && loggedInAccounts.length > 0) {
      for (i in loggedInAccounts) {
        account = loggedInAccounts[i];
        if (account.index === delegatedToUserIndex) {
          return account.email;
        }
      }
    }

    // as a last resort, we query the DOM of the upper right account selection menu
    return $(".gb_rb[href$='" + userIndexPrefix + delegatedToUserIndex + "'] .gb_yb").text().split(" ")[0];
  };


  api.get.localization = function() {
    var isLocale = function(locale) {
      // A locale is a string that begins with 2 letters, lowercase.
      // The 'lowercase' check distinguishes locales from other 2-letter strings like 'US'
      // (the user's location?).
      if (!locale || ((typeof locale) !== 'string') || locale.length < 2) {
        return false;
      }

      var localePrefix = locale.slice(0, 2);
      return localePrefix.toLowerCase() === localePrefix;
    };

    var globals = api.tracker.globals;

    // First candidate.
    var locale = globals[17] && globals[17][8] && globals[17][8][8];
    if (isLocale(locale)) {
      return locale;
    }

    // Second candidate.
    locale = globals[17] && globals[17][9] && globals[17][9][8];
    if (isLocale(locale)) {
      return locale;
    }

    return null;
  };


  api.check.is_thread = function() {
    var check_1 = $('.nH .if').children(":eq(1)").children().children(":eq(1)").children();
    var check_2 = api.get.email_ids();

    return check_1.length > 1 || check_2.length > 1;
  };


  api.dom.inbox_content = function() {
    return $('div[role=main]:first');
  };


  api.check.is_preview_pane = function() {
    var dom = api.dom.inbox_content();
    var boxes = dom.find("[gh=tl]");

    var previewPaneFound = false;
    boxes.each(function() {
      if($(this).hasClass('aia')) {
        previewPaneFound = true;
      }
    });

    return previewPaneFound;
  };

  api.check.is_multiple_inbox = function() {
    var dom = api.dom.inboxes();
    return dom.length > 1;
  };


  api.check.is_horizontal_split = function() {
    var dom = api.dom.inbox_content();
    var box = dom.find("[gh=tl]").find('.nn');

    return box.length == 0;
  };


  api.check.is_vertical_split = function() {
    return api.check.is_horizontal_split() == false;
  };


  api.check.is_tabbed_inbox = function() {
    return $(".aKh").length == 1;
  };


  api.check.is_right_side_chat = function() {
    var chat = $('.ApVoH');
    if(chat.length === 0) {
      return false;
    }

    return chat[0].getAttribute('aria-labelledby') == ':wf';
  }

  api.check.should_compose_fullscreen = function(){
    var bx_scfs = [];
    try {
      bx_scfs = api.tracker.globals[17][4][1][32];
    } catch(er) {
      bx_scfs = ['bx_scfs','false'];
    }
     return (bx_scfs[1] == 'true' ) ? true : false;
  }


  api.check.is_google_apps_user =function() {
    var email = api.get.user_email();
    return email.indexOf('gmail.com', email.length - 'gmail.com'.length) == -1;
  };


  api.get.storage_info = function() {
    var div = $('.md.mj').find('div')[0];
    var used = $(div).find('span')[0].text;
    var total = $(div).find('span')[1].text;
    var percent = parseFloat(used.replace(/[^0-9\.]/g, '')) * 100 / parseFloat(total.replace(/[^0-9\.]/g, ''));

    return {used : used, total : total, percent : Math.floor(percent)}
  };


  api.dom.inboxes = function() {
    var dom = api.dom.inbox_content();
    return dom.find("[gh=tl]");
  };

  api.dom.email_subject = function () {
    var e = $(".hP");

    for(var i=0; i<e.length; i++) {
      if($(e[i]).is(':visible')) {
        return $(e[i]);
      }
    }

    return $();
  };


  api.get.email_subject = function() {
    var subject_dom = api.dom.email_subject();

    return subject_dom.text();
  };


  api.dom.email_body = function() {
    return $('.nH.hx');
  };

  api.dom.toolbar = function() {
    var tb = $("[gh='mtb']");

    while($(tb).children().length == 1){
      tb = $(tb).children().first();
    }

    return tb;
};


  api.check.is_inside_email = function() {
    if(api.get.current_page() != 'email' && !api.check.is_preview_pane()) {
      return false;
    }

    var items = $('.ii.gt .a3s.aXjCH');
    var ids = [];

    for(var i=0; i<items.length; i++) {
      var mail_id = items[i].getAttribute('class').split(' ')[2];
      if(mail_id != 'undefined' && mail_id != undefined) {
        if($(items[i]).is(':visible')) {
          ids.push(items[i]);
        }
      }
    }

    return ids.length > 0;
  };

  api.check.is_plain_text = function() {
    var settings = GLOBALS[17][4][1];

    for (var i = 0; i < settings.length; i++) {
      var plain_text_setting = settings[i];
      if (plain_text_setting[0] === 'bx_cm') {
        return plain_text_setting[1] === '0';
      }
    }

    // default to rich text mode, which is more common nowadays
    return false;
  };

  api.dom.email_contents = function() {
    var items = $('.ii.gt div.a3s.aXjCH');
    var ids = [];

    for(var i=0; i<items.length; i++) {
      var mail_id = items[i].getAttribute('class').split(' ')[2];
      var is_editable = items[i].getAttribute('contenteditable');
      if(mail_id != 'undefined' && mail_id != undefined) {
        if(is_editable != 'true') {
          ids.push(items[i]);
        }
      }
    }

    return ids;
  };


  api.get.email_ids = function() {
    if(api.check.is_inside_email()) {
      var data = api.get.email_data();
      return Object.keys(data.threads);
    }
    return [];
  };


  api.get.compose_ids = function() {
      var ret = [];
      var dom = $(".AD [name=draft]");
      for(var i = 0; i < dom.length; i++) {
          if(dom[i].value != "undefined"){
              ret.push(dom[i].value);
          }
      }
      return ret;
  };


  api.get.email_id = function() {
    var hash = null;

    if(api.check.is_inside_email()) {
      if(api.check.is_preview_pane()) {
        var items = api.dom.email_contents();
        var text = [];

        for(var i=0; i<items.length; i++) {
          var mail_id = items[i].getAttribute('class').split(' ')[2];
          var is_editable = items[i].getAttribute('contenteditable');
          var is_visible = items[i].offsetWidth > 0 && items[i].offsetHeight > 0;
          if(mail_id != 'undefined' && mail_id != undefined && is_visible) {
            if(is_editable != 'true') {
              text.push(mail_id);
            }
          }
        }

        hash = text[0].substring(1, text[0].length);
      } else {
        hash = window.location.hash.split("/").pop().replace(/#/, '').split('?')[0];
      }
    }
{'fraction_non_alphanumeric': 0.17794008680004234, 'fraction_numerical': 0.012543664655446173, 'mean_word_length': 2.268465663380038, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '707819', 'n_tokens_mistral': 6580, 'n_tokens_neox': 6303, 'n_words': 1293}