forked from KartikTalwar/gmail.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmail.min.js
1 lines (1 loc) · 28.3 KB
/
gmail.min.js
1
var Gmail=function(localJQuery){var $;if(typeof localJQuery!=="undefined")$=localJQuery;else if(typeof jQuery!=="undefined")$=jQuery;var api={get:{},observe:{},check:{},tools:{},tracker:{},dom:{},chat:{},compose:{}};api.version="0.2.2";api.tracker.globals=GLOBALS;api.tracker.view_data=typeof VIEW_DATA!=="undefined"?VIEW_DATA:[];api.tracker.ik=api.tracker.globals[9];api.tracker.hangouts=undefined;api.get.last_active=function(){var e=api.tracker.globals[17][15];return{time:e[1],ip:e[3],mac_address:e[9],time_relative:e[10]}};api.get.loggedin_accounts=function(){var e=api.tracker.globals[17][23];var t=[];for(i in e[1]){t.push({name:e[1][i][4],email:e[1][i][0]})}return t};api.get.user_email=function(){return api.tracker.globals[10]};api.check.is_thread=function(){var e=$(".nH .if").children(":eq(1)").children().children(":eq(1)").children();var t=api.get.email_ids();return e.length>1||t.length>1};api.dom.inbox_content=function(){return $("div[role=main]:first")};api.check.is_preview_pane=function(){var e=api.dom.inbox_content();var t=e.find("[gh=tl]");var n=false;t.each(function(){if($(this).hasClass("aia")){n=true}});return n};api.check.is_multiple_inbox=function(){var e=api.dom.inboxes();return e.length>1};api.check.is_horizontal_split=function(){var e=api.dom.inbox_content();var t=e.find("[gh=tl]").find(".nn");return t.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(){return $(".ApVoH")[0].getAttribute("aria-labelledby")==":wf"};api.check.is_google_apps_user=function(){var e=api.get.user_email();return e.indexOf("gmail.com",e.length-"gmail.com".length)==-1};api.get.storage_info=function(){var e=$(".md.mj").find("div")[0];var t=$(e).find("span")[0].text;var n=$(e).find("span")[1].text;var r=parseFloat(t.replace(/[^0-9\.]/g,""))*100/parseFloat(n.replace(/[^0-9\.]/g,""));return{used:t,total:n,percent:Math.floor(r)}};api.dom.inboxes=function(){var e=api.dom.inbox_content();return e.find("[gh=tl]")};api.dom.email_subject=function(){var e=$(".hP");for(var t=0;t<e.length;t++){if($(e[t]).is(":visible")){return $(e[t])}}return $()};api.get.email_subject=function(){var e=api.dom.email_subject();return e.text()};api.dom.email_body=function(){return $(".nH.hx")};api.check.is_inside_email=function(){if(api.get.current_page()!=null&&!api.check.is_preview_pane()){return false}var e=$(".ii.gt");var t=[];for(var n=0;n<e.length;n++){var r=e[n].getAttribute("class").split(" ")[2];if(r!="undefined"&&r!=undefined){if($(e[n]).is(":visible")){t.push(e[n])}}}return t.length>0};api.dom.email_contents=function(){var e=$(".ii.gt");var t=[];for(var n=0;n<e.length;n++){var r=e[n].getAttribute("class").split(" ")[2];var i=e[n].getAttribute("contenteditable");if(r!="undefined"&&r!=undefined){if(i!="true"){t.push(e[n])}}}return t};api.get.email_ids=function(){if(api.check.is_inside_email()){var e=api.get.email_data();return Object.keys(e.threads)}return[]};api.get.compose_ids=function(){var e=[];var t=$(".AD [name=draft]");for(var n=0;n<t.length;n++){if(t[n].value!="undefined"){e.push(t[n].value)}}return e};api.get.email_id=function(){var e=null;if(api.check.is_inside_email()){if(api.check.is_preview_pane()){var t=api.dom.email_contents();var n=[];for(var r=0;r<t.length;r++){var i=t[r].getAttribute("class").split(" ")[2];var s=t[r].getAttribute("contenteditable");if(i!="undefined"&&i!=undefined){if(s!="true"){n.push(i)}}}e=n[0].substring(1,n[0].length)}else{e=window.location.hash.split("/").pop().replace(/#/,"").split("?")[0]}}return e};api.check.is_priority_inbox=function(){return $(".qh").length>0};api.check.is_rapportive_installed=function(){return $("#rapportive-sidebar").length==1};api.check.is_streak_installed=function(){return $("[id^='bentoBox'],[id*=' bentoBox'],[class*=' bentoBox'],[class*='bentoBox']").length>0};api.check.is_anydo_installed=function(){return $("[id^='anydo'],[id*=' anydo'],[class*=' anydo'],[class*='anydo']").length>0};api.check.is_boomerang_installed=function(){return $("[id^='b4g_'],[id*=' b4g_'],[class*=' b4g_'],[class*='b4g_']").length>0};api.check.is_xobni_installed=function(){return $("#xobni_frame").length>0};api.check.is_signal_installed=function(){return $("[id^='Signal'],[id*=' Signal'],[class*=' signal'],[class*='signal']").length>0};api.check.are_shortcuts_enabled=function(){var e="bx_hs";var t=undefined;var n=true;var r=api.tracker.globals[17][5][1];for(var i=0;i<r.length;i++){var s=r[i];if(s[0]===e){t=s[1];break}}if(t!==undefined){var o={0:true,1:false};n=o[t]}return n};api.dom.get_left_sidebar_links=function(){return $("div[role=navigation] [title]")};api.dom.search_bar=function(){return $("[gh=sb]")};api.get.search_query=function(){var e=api.dom.search_bar();return e.find("input")[0].value};api.get.unread_inbox_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("inbox")+"']");if(e.length>0){if(e[0].text.indexOf("(")!=-1){return parseInt(e[0].text.replace(/[^0-9]/g,""))}}return 0};api.get.unread_draft_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("drafts")+"']");if(e.length>0){if(e[0].text.indexOf("(")!=-1){return parseInt(e[0].text.replace(/[^0-9]/g,""))}}return 0};api.get.unread_spam_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("spam")+"']");if(e.length>0){if(e[0].text.indexOf("(")!=-1){return parseInt(e[0].text.replace(/[^0-9]/g,""))}}return 0};api.get.unread_forum_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("forums")+"']");if(e.length>0){if(e[0].text.indexOf("(")!=-1){return parseInt(e[0].text.replace(/[^0-9]/g,""))}}return 0};api.get.unread_update_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("updates")+"']");if(e.length>0){if(e[0].text.indexOf("(")!=-1){return parseInt(e[0].text.replace(/[^0-9]/g,""))}}return 0};api.get.unread_promotion_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("promotions")+"']");if(e.length>0){if(e[0].text.indexOf("(")!=-1){return parseInt(e[0].text.replace(/[^0-9]/g,""))}}return 0};api.get.unread_social_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("social_updates")+"']");if(e.length>0){if(e[0].text.indexOf("(")!=-1){return parseInt(e[0].text.replace(/[^0-9]/g,""))}}return 0};api.get.beta=function(){var e={new_nav_bar:$("#gbz").length==0};return e};api.get.unread_emails=function(){return{inbox:api.get.unread_inbox_emails(),drafts:api.get.unread_draft_emails(),spam:api.get.unread_spam_emails(),forum:api.get.unread_forum_emails(),update:api.get.unread_update_emails(),promotions:api.get.unread_promotion_emails(),social:api.get.unread_social_emails()}};api.tools.parse_url=function(e){var t=/[?&]([^=#]+)=([^&#]*)/g;var n={};var r;while(r=t.exec(e)){n[r[1]]=r[2]}return n};api.tools.sleep=function(e){var t=(new Date).getTime();while(true){if((new Date).getTime()-t>e){break}}};api.tools.multitry=function(e,t,n,r,i,s){if(i!=undefined&&i>=t){return s}var i=i==undefined?0:i;var o=n();if(r(o)){return o}else{api.tools.sleep(e);api.tools.multitry(e,t,n,r,i+1,o)}};api.tools.deparam=function(e,t){var n=function(e,t){var n=[];for(i=0;i<e.length;i++){n.push(t(e[i]))}return n};var r=Array.isArray||function(e){return Object.prototype.toString.call(e)=="[object Array]"};var s={},o={"true":!0,"false":!1,"null":null};n(e.replace(/\+/g," ").split("&"),function(e,n){var i=e.split("="),u=decodeURIComponent(i[0]),a,f=s,l=0,c=u.split("]["),h=c.length-1;if(/\[/.test(c[0])&&/\]$/.test(c[h])){c[h]=c[h].replace(/\]$/,"");c=c.shift().split("[").concat(c);h=c.length-1}else{h=0}if(i.length===2){a=decodeURIComponent(i[1]);if(t){a=a&&!isNaN(a)?+a:a==="undefined"?undefined:o[a]!==undefined?o[a]:a}if(h){for(;l<=h;l++){u=c[l]===""?f.length:c[l];f=f[u]=l<h?f[u]||(c[l+1]&&isNaN(c[l+1])?{}:[]):a}}else{if(r(s[u])){s[u].push(a)}else if(s[u]!==undefined){s[u]=[s[u],a]}else{s[u]=a}}}else if(u){s[u]=t?undefined:""}});return s};api.tools.parse_actions=function(e,t){if(e.url.act=="fup"||e.url.act=="fuv"||e.body_is_object){return e.body_is_object&&api.observe.bound("upload_attachment")?{upload_attachment:[e.body_params]}:false}if(e.method=="POST"&&typeof e.url.act=="string"){}if(e.url.search!=undefined){}var n={};var r={tae:"add_to_tasks","rc_^i":"archive",tr:"delete",dm:"delete_message_in_thread",dl:"delete_forever",dc_:"delete_label",dr:"discard_draft",el:"expand_categories",cffm:"filter_messages_like_these",arl:"label",mai:"mark_as_important",mani:"mark_as_not_important",us:"mark_as_not_spam",sp:"mark_as_spam",mt:"move_label",ib:"move_to_inbox",ig:"mute",rd:"read",sd:"save_draft",sm:"send_message",mo:"show_newly_arrived_message",st:"star",ug:"unmute",ur:"unread",xst:"unstar",new_mail:"new_email",poll:"poll",refresh:"refresh",rtr:"restore_message_in_thread",open_email:"open_email",toggle_threads:"toggle_threads"};if(typeof e.url.ik=="string"){api.tracker.ik=e.url.ik}if(typeof e.url.rid=="string"){if(e.url.rid.indexOf("mail")!=-1){api.tracker.rid=e.url.rid}}var i=decodeURIComponent(e.url.act);var s=e.body_params;var o=typeof s.t=="string"?[s.t]:s.t;var u=null;switch(i){case"ur":case"rd":case"tr":case"sp":case"us":case"ib":case"dl":case"st":case"xst":case"mai":case"mani":case"ig":case"ug":case"dr":case"mt":case"cffm":case"rc_^i":u=[o,e.url,e.body];break;case"arl":u=[o,e.url,e.body,e.url.acn];break;case"sd":u=[o,e.url,s];break;case"tae":case"sm":u=[e.url,e.body,s];break;case"el":u=[e.url,e.body,s.ex=="1"];break;case"dm":case"rtr":u=[s.m,e.url,e.body];break}if(typeof e.url._reqid=="string"&&typeof e.url.th=="string"){u=[e.url.th,e.url,e.body];if(api.observe.bound("new_email")){n.new_email=u}}if((e.url.view=="cv"||e.url.view=="ad")&&typeof e.url.th=="string"&&typeof e.url.search=="string"&&e.url.rid==undefined){u=[e.url.th,e.url,e.body];if(api.observe.bound("open_email")){n.open_email=u}}if((e.url.view=="cv"||e.url.view=="ad")&&typeof e.url.th=="object"&&typeof e.url.search=="string"&&e.url.rid!=undefined){u=[e.url.th,e.url,e.body];if(api.observe.bound("toggle_threads")){n.toggle_threads=u}}if((e.url.view=="cv"||e.url.view=="ad")&&typeof e.url.th=="string"&&typeof e.url.search=="string"&&e.url.rid!=undefined){if(e.url.msgs!=undefined){u=[e.url.th,e.url,e.body];if(api.observe.bound("toggle_threads")){n.toggle_threads=u}}}if(typeof e.url.SID=="string"&&typeof e.url.zx=="string"&&e.body.indexOf("req0_")!=-1){api.tracker.SID=e.url.SID;u=[e.url,e.body,s];if(api.observe.bound("poll")){n.poll=u}}if(typeof e.url.ik=="string"&&typeof e.url.search=="string"&&e.body.length==0&&typeof e.url._reqid=="string"){u=[e.url,e.body,s];if(api.observe.bound("refresh")){n.refresh=u}}if(u&&r[i]&&api.observe.bound(r[i])){n[r[i]]=u}return n};api.tools.parse_response=function(response){var parsedResponse=[],data,dataLength,endIndex,realData;try{response=response.replace(/\n/g," ");response=response.substring(response.indexOf("'")+1,response.length);while(response.replace(/\s/g,"").length>1){dataLength=response.substring(0,response.indexOf("[")).replace(/\s/g,"");if(!dataLength){dataLength=response.length}endIndex=parseInt(dataLength,10)-2+response.indexOf("[");data=response.substring(response.indexOf("["),endIndex);realData=eval(data);parsedResponse.push(realData);response=response.substring(response.indexOf("["),response.length);response=response.substring(data.length,response.length)}}catch(e){console.log("Gmail post response parsing failed.",e)}return parsedResponse};api.tools.parse_requests=function(e,t){e.url_raw=e.url;e.url=api.tools.parse_url(e.url);if(typeof e.body=="object"){e.body_params=e.body;e.body_is_object=true}else{e.body_params=api.tools.deparam(e.body)}if(typeof api.tracker.events!="object"&&typeof api.tracker.actions!="object"){api.tracker.events=[];api.tracker.actions=[]}api.tracker.events.unshift(e);var n=api.tools.parse_actions(e,t);if(e.method=="POST"&&typeof e.url.act=="string"){api.tracker.actions.unshift(e)}if(api.tracker.events.length>50){api.tracker.events.pop()}if(api.tracker.actions.length>10){api.tracker.actions.pop()}return n};api.tools.xhr_watcher=function(){if(!api.tracker.xhr_init){var e=top.document.getElementById("js_frame").contentDocument.defaultView;api.tracker.xhr_init=true;api.tracker.xhr_open=e.XMLHttpRequest.prototype.open;api.tracker.xhr_send=e.XMLHttpRequest.prototype.send;e.XMLHttpRequest.prototype._gjs_open=e.XMLHttpRequest.prototype.open;e.XMLHttpRequest.prototype.open=function(e,t,n,r,i){var s=this._gjs_open.apply(this,arguments);this.xhrParams={method:e.toString(),url:t.toString()};return s};e.XMLHttpRequest.prototype._gjs_send=e.XMLHttpRequest.prototype.send;e.XMLHttpRequest.prototype.send=function(e){var t=false;if(this.xhrParams){this.xhrParams.body=e;t=api.tools.parse_requests(this.xhrParams,this)}if(api.observe.trigger("before",t,this)){e=arguments[0]=this.xhrParams.body_is_object?this.xhrParams.body_params:$.param(this.xhrParams.body_params,true)}if(api.observe.bound(t,"after")){var n=this.onreadystatechange;var r=this;this.onreadystatechange=function(e){if(this.readyState===this.DONE){r.xhrResponse=api.tools.parse_response(e.target.responseText);api.observe.trigger("after",t,r)}if(n){n.apply(this,arguments)}}}var i=this._gjs_send.apply(this,arguments);api.observe.trigger("on",t,this);return i}}};api.observe.http_requests=function(){return api.tracker.events};api.observe.actions=function(){return api.tracker.actions};api.observe.bind=function(e,t,n){if(typeof api.tracker.watchdog!="object"){api.tracker.watchdog={before:{},on:{},after:{},dom:{}};api.tracker.bound={}}if(typeof api.tracker.watchdog[e]!="object"){throw"api.observe.bind called with invalid type: "+e}if(e!="dom"&&!api.tracker.xhr_init){api.tools.xhr_watcher()}if(typeof api.tracker.watchdog[e][t]!="object"){api.tracker.watchdog[e][t]=[]}api.tracker.watchdog[e][t].push(n);api.tracker.bound[t]=typeof api.tracker.bound[t]=="undefined"?1:api.tracker.bound[t]+1;api.tracker.bound[e]=typeof api.tracker.bound[e]=="undefined"?1:api.tracker.bound[e]+1};api.observe.on=function(e,t,n){if(api.observe.on_dom(e,t))return true;api.observe.bind("on",e,t);if(n){api.observe.after(e,t)}};api.observe.before=function(e,t){api.observe.bind("before",e,t)};api.observe.after=function(e,t){api.observe.bind("after",e,t)};api.observe.bound=function(e,t){if(typeof api.tracker.watchdog!="object")return false;if(e){if(typeof e=="object"){var n=false;$.each(e,function(e,r){if(typeof api.tracker.watchdog[t][e]=="object")n=true});return n}if(t)return typeof api.tracker.watchdog[t][e]=="object";return api.tracker.bound[e]>0}else{if(t)return api.tracker.bound[t]>0;throw"api.observe.bound called with invalid args"}};api.observe.off=function(e,t){if(typeof api.tracker.watchdog!="object")return true;if(!t&&!e){var n=top.document.getElementById("js_frame").contentDocument.defaultView;n.XMLHttpRequest.prototype.open=api.tracker.xhr_open;n.XMLHttpRequest.prototype.send=api.tracker.xhr_send;api.tracker.xhr_init=false}var r=t?[t]:["before","on","after","dom"];$.each(r,function(t,n){if(typeof api.tracker.watchdog[n]!="object")return true;if(e){if(typeof api.tracker.watchdog[n][e]=="object"){api.tracker.bound[e]-=api.tracker.watchdog[n][e].length;api.tracker.bound[n]-=api.tracker.watchdog[n][e].length;delete api.tracker.watchdog[n][e]}}else{$.each(api.tracker.watchdog[n],function(e,t){if(typeof api.tracker.watchdog[n][e]=="object"){api.tracker.bound[e]-=api.tracker.watchdog[n][e].length;api.tracker.bound[n]-=api.tracker.watchdog[n][e].length;delete api.tracker.watchdog[n][e]}})}})};api.observe.trigger=function(e,t,n){if(!t)return false;var r=false;$.each(t,function(t,i){i=$.extend([],i);if(e=="after")i.push(n.xhrResponse);i.push(n);if(api.observe.bound(t,e)){r=true;$.each(api.tracker.watchdog[e][t],function(e,t){t.apply(undefined,i)})}});return r};api.observe.trigger_dom=function(e,t,n){if(!n){n=function(e,t){t(e)}}if(!api.tracker.watchdog.dom[e]){return}$.each(api.tracker.watchdog.dom[e],function(e,r){n(t,r)})};api.observe.on_dom=function(e,t){if(!api.tracker.supported_observers){api.tracker.supported_observers=["view_thread","view_email","load_email_menu","recipient_change","compose"];api.tracker.dom_observers={view_thread:{"class":["Bu","Bs"],sub_selector:"div.if",handler:function(e,t){e=new api.dom.thread(e);t(e);var n=e.dom("opened_email");if(n.length){api.observe.trigger_dom("view_email",n,api.tracker.dom_observers.view_thread.sub_observers.view_email.handler)}},sub_observers:{view_email:{"class":"",sub_selector:"div.adn",handler:function(e,t){e=new api.dom.email(e);t(e)}},load_email_menu:{"class":"J-N",selector:"div[role=menu] div[role=menuitem]:first-child",handler:function(e,t){e=e.closest("div[role=menu]");t(e)}}}},recipient_change:{"class":"vR",handler:function(e,t){if(typeof api.tracker.recipient_matches!="object"){api.tracker.recipient_matches=[]}api.tracker.recipient_matches.push(e);setTimeout(function(){if(!api.tracker.recipient_matches.length)return;var e=new api.dom.compose(api.tracker.recipient_matches[0].closest("div.M9"));var n=e.recipients();t(e,n,api.tracker.recipient_matches);api.tracker.recipient_matches=[]},100)}},compose:{"class":"An",handler:function(e,t){e=e.closest("div.M9");if(!e.length)return;e=new api.dom.compose(e);var n;if(e.is_inline()){n=e.find("input[name=subject]").val().indexOf("Fw")==0?"forward":"reply"}else{n="compose"}t(e,n)}}};api.tracker.dom_observer_map={};$.each(api.tracker.dom_observers,function(e,t){if(!$.isArray(t.class))t.class=[t.class];$.each(t.class,function(t,n){api.tracker.dom_observer_map[n]=e})})}if($.inArray(e,api.tracker.supported_observers)>-1){if(!api.tracker.observing_dom){api.tracker.observing_dom=true;$(window.document).bind("DOMNodeInserted",function(e){api.tools.insertion_observer(e.target,api.tracker.dom_observers,api.tracker.dom_observer_map)})}api.observe.bind("dom",e,t);return true}else if(e=="load"){if(api.dom.inbox_content().length)return t();var n=0;var r=200;var i=50;var s=setInterval(function(){var e=api.dom.inbox_content().length;if(e>0){clearInterval(s);return t()}else if(++n>i){clearInterval(s);console.log("Failed to detect interface load in "+r*i/1e3+" seconds. Will automatically fire event in 5 further seconds.");setTimeout(t,5e3)}},r);return true}};api.tools.insertion_observer=function(e,t,n,r){if(!api.tracker.dom_observer_map)return;var i=e.className.trim().split(/\s+/);if(!i.length)i.push("");$.each(i,function(r,i){var s=n[i];if(s&&api.tracker.watchdog.dom[s]){var o=$(e);var u=t[s];if(u.selector&&!o.is(u.selector)){return}if(u.sub_selector){o=o.find(u.sub_selector)}if(o.length){var a=u.handler?u.handler:function(e,t){t(e)};api.observe.trigger_dom(s,o,a);if(u.sub_observers){var f={};$.each(u.sub_observers,function(e,t){f[t.class]=e});o.bind("DOMNodeInserted",function(e){api.tools.insertion_observer(e.target,u.sub_observers,f,"SUB ")})}}}})};api.tools.make_request=function(e,t){var t=typeof t==undefined||typeof t==null?"GET":t;var n=$.ajax({type:t,url:encodeURI(e),async:false});return n.responseText};api.tools.parse_view_data=function(e){var t=[];var n=[];for(var r=0;r<e.length;r++){if(e[r][0]=="tb"){for(var i=0;i<e[r][2].length;i++){n.push(e[r][2][i])}}}for(var s=0;s<n.length;s++){var o=n[s];var u={};t.push({id:o[0],title:o[9],excerpt:o[10],time:o[15],sender:o[28],attachment:o[13],labels:o[5]})}return t};api.get.visible_emails=function(){var page=api.get.current_page();var url=window.location.origin+window.location.pathname+"?ui=2&ik="+api.tracker.ik+"&rid="+api.tracker.rid+"&view=tl&start=0&num=120&rt=1";if(page.indexOf("label/")==0){url+="&cat="+page.split("/")[1]+"&search=cat"}else if(page.indexOf("category/")==0){if(page.indexOf("forums")!=-1){cat_label="group"}else if(page.indexOf("updates")!=-1){cat_label="notification"}else if(page.indexOf("promotion")!=-1){cat_label="promo"}else if(page.indexOf("social")!=-1){cat_label="social"}url+="&cat=^smartlabel_"+cat_label+"&search=category"}else if(page.indexOf("search/")==0){url+="&qs=true&q="+page.split("/")[1]+"&search=query"}else{url+="&search="+page}var get_data=api.tools.make_request(url);get_data=get_data.substring(get_data.indexOf("["),get_data.length);get_data="api.tracker.view_data = "+get_data;eval(get_data);var emails=[];for(i in api.tracker.view_data){if(typeof api.tracker.view_data[i]==="function"){continue}var cdata=api.tools.parse_view_data(api.tracker.view_data[i]);if(cdata.length>0){$.merge(emails,cdata)}}return emails};api.get.current_page=function(){var e=window.location.hash.split("#").pop();var t=["sent","inbox","starred","drafts","imp","chats","all","spam","trash","settings"];var n=null;if($.inArray(e,t)>-1){n=e}if(e.indexOf("label/")==0||e.indexOf("category/")==0||e.indexOf("search/")==0||e.indexOf("settings/")==0){if(e.split("/").length<3){n=e}}return n};api.tools.infobox=function(e,t,n){var r=$(".b8.UC");if(r.length>0){r.stop(false,true);var i=r.find(".vh");if(!n){i.text(e)}else{i.html(e)}if(typeof t!=="undefined"){var s=r.attr("style");r.removeAttr("style").fadeTo(t,0,function(){$(this).attr("style",s)})}else{r.removeAttr("style")}}};api.tools.parse_email_data=function(e){var t={};var n={};for(i in e){var r=e[i];if(r[0]=="cs"){t.first_email=r[1];t.last_email=r[2];t.total_emails=r[3];t.total_threads=r[8];t.people_involved=r[15];t.subject=r[23]}if(r[0]=="ms"){if(t.threads==undefined){t.threads={}}t.threads[r[1]]={};t.threads[r[1]].is_deleted=r[13]==undefined;t.threads[r[1]].reply_to_id=r[2];t.threads[r[1]].from=r[5];t.threads[r[1]].from_email=r[6];t.threads[r[1]].timestamp=r[7];t.threads[r[1]].datetime=r[24];t.threads[r[1]].attachments=r[21].split(",");t.threads[r[1]].subject=r[12];t.threads[r[1]].content_html=r[13]!=undefined?r[13][6]:r[8];t.threads[r[1]].to=r[13]!=undefined?r[13][1]:r[37]!=undefined?r[37][1]:[];t.threads[r[1]].cc=r[13]!=undefined?r[13][2]:[];t.threads[r[1]].bcc=r[13]!=undefined?r[13][3]:[];try{t.threads[r[1]].content_plain=r[13]!=undefined?$(r[13][6]).text():r[8]}catch(s){t.threads[r[1]].content_plain=r[13]!=undefined?r[13][6]:r[8]}}}return t};api.get.email_data=function(email_id){if(api.check.is_inside_email()&&email_id==undefined){email_id=api.get.email_id()}if(email_id!=undefined){var url=window.location.origin+window.location.pathname+"?ui=2&ik="+api.tracker.ik+"&rid="+api.tracker.rid+"&view=cv&th="+email_id+"&msgs=&mb=0&rt=1&search=inbox";var get_data=api.tools.make_request(url);get_data=get_data.substring(get_data.indexOf("["),get_data.length);get_data="var cdata = "+get_data;eval(get_data);api.tracker.email_data=cdata[0];return api.tools.parse_email_data(api.tracker.email_data)}return{}};api.get.email_source=function(e){if(api.check.is_inside_email()&&e==undefined){e=api.get.email_id()}if(e!=undefined){var t=window.location.origin+window.location.pathname+"?ui=2&ik="+api.tracker.ik+"&view=om&th="+e;return api.tools.make_request(t)}return""};api.get.displayed_email_data=function(){var e=api.get.email_data();var t={};if(api.check.is_conversation_view()){t=e;var n=t.threads;var r=t.total_threads;var i=window.location.hash.split("#")[1]||"";var s=i.indexOf("trash")===0;for(id in n){var o=n[id];var u=s?o.is_deleted:!o.is_deleted;if(!u){delete n[id];r.splice(r.indexOf(id),1);t.total_emails--}}}else{for(id in e.threads){var a=$('.ii.gt[class*="'+id+'"]');if(a.length>0){var o=e.threads[id];t.first_email=id;t.last_email=id;t.subject=e.subject;t.threads={};t.threads[id]=o;t.total_emails=1;t.total_threads=[id];t.people_involved=[];t.people_involved.push([o.from,o.from_email]);o.to.forEach(function(e){var n=api.tools.extract_email_address(e);var r=api.tools.extract_name(e.replace(n,""))||"";t.people_involved.push([r,n])});break}}}return t};api.check.is_conversation_view=function(){var e="bx_vmb";var t=undefined;var n=api.tracker.globals[17][5][1];for(var r=0;r<n.length;r++){var i=n[r];if(i[0]===e){t=i[1];break}}return t==="0"||t===undefined};api.tools.extract_email_address=function(e){var t=/[\+a-z0-9._-]+@[a-z0-9._-]+\.[a-z0-9._-]+/gi;var n=e?e.match(t):undefined;return n?n[0]:undefined};api.tools.extract_name=function(e){var t=/[a-z'._-\s]+/gi;var n=e?e.match(t):undefined;return n&&n[0]?n[0].trim():undefined};api.tools.i18n=function(e){var t=api.tracker.globals[17][9][8];var n;switch(t){case"fr":n={inbox:"Boîte de réception",drafts:"Brouillons",spam:"Spam",forums:"Forums",updates:"Mises à jour",promotions:"Promotions",social_updates:"Réseaux sociaux"};break;case"nl":n={inbox:"Postvak IN",drafts:"Concepten",spam:"Spam",forums:"Forums",updates:"Updates",promotions:"Reclame",social_updates:"Sociaal"};break;case"en":default:n={inbox:"Inbox",drafts:"Drafts",spam:"Spam",forums:"Forums",updates:"Updates",promotions:"Promotions",social_updates:"Social Updates"};break}return n[e]};api.chat.is_hangouts=function(){if(api.tracker.hangouts!=undefined){return api.tracker.hangouts}var e=$(".dw");if(e.length>1){throw"Figuring out is hangouts - more than one dw classes found"}if(e.length==0){throw"Figuring out is hangouts - no dw classes found"}var t=e[0];var n=$(".nH.aJl.nn",t);if(n.length>0){api.tracker.hangouts=true;return true}var n=$(".nH.nn",t);if(n.length>2){api.tracker.hangouts=false;return false}return undefined};api.dom.composes=function(){objs=[];$("div.AD").each(function(e,t){objs.push(new api.dom.compose($(t).find("div.M9")))});return objs};api.dom.compose=function(e){e=$(e);if(!e||!e.hasClass("M9")&&!e.hasClass("AD"))throw"api.dom.compose called with invalid element";this.$el=e;return this};$.extend(api.dom.compose.prototype,{id:function(){return this.dom("id").val()},is_inline:function(){return this.$el.closest("td.Bu").length>0},recipients:function(e){if(typeof e!="object")e={};var t=e.type?"[name="+e.type+"]":"";var n=e.flat?[]:{};this.$el.find(".GS input[type=hidden]"+t).each(function(t,r){if(e.flat){n.push(r.value)}else{if(!n[r.name])n[r.name]=[];n[r.name].push(r.value)}});return n},to:function(e){return this.recipients({type:"to",flat:true})},cc:function(){return this.recipients({type:"cc",flat:true})},bcc:function(){return this.recipients({type:"bcc",flat:true})},subject:function(e){var t=this.dom("subjectbox");if(e)this.dom("all_subjects").val(e);e=this.dom("subjectbox").val();return e?e:this.dom("subject").val()},body:function(e){var t=this.dom("body");if(e)t.html(e);return t.html()},find:function(e){return this.$el.find(e)},dom:function(e){if(!e)return this.$el;var t={id:"input[name=composeid]",subject:"input[name=subject]",subjectbox:"input[name=subjectbox]",body:"div[contenteditable=true]",reply:"M9",forward:"M9"};if(!t[e])throw"Dom lookup failed. Unable to find config for '"+e+"'",t,e,t[e];return this.$el.find(t[e])}});api.dom.email=function(e){if(typeof e=="string"){this.id=e;this.id_element=$("div.ii.gt.m"+this.id);e=this.id_element.closest("div.adn")}else{e=$(e)}if(!e||!e.hasClass("adn"))throw"api.dom.email called with invalid element/id";if(!this.id){this.id_element=e.find("div.ii.gt");this.id=this.id_element.attr("class").match(/(^|\s)m([\S]*)/).pop()}this.$el=e;return this};$.extend(api.dom.email.prototype,{body:function(e){var t=this.dom("body");if(e){t.html(e)}return t.html()},from:function(e,t){var n=this.dom("from");if(e){n.attr("email",e)}if(t){n.attr("name",t);n.html(t)}return{email:n.attr("email"),name:n.attr("name"),el:n}},to:function(e){if(e){if(!$.isArray(e)){e=[e]}var t=[];$.each(e,function(e,n){t.push($("<span />").attr({dir:"ltr",email:n.email,name:n.name}).addClass("g2").html(n.name).wrap("<p/>").parent().html())});this.dom("to_wrapper").html("to "+t.join(", "))}var n=new Array;this.dom("to").each(function(e){el=$(this);n.push({email:el.attr("email"),name:el.attr("name"),el:el})});return n},data:function(){if(typeof api.dom.email_cache!="object"){api.dom.email_cache={}}if(!api.dom.email_cache[this.id]){var e=api.get.email_data(this.id);$.each(e.threads,function(e,t){api.dom.email_cache[e]=t})}return api.dom.email_cache[this.id]},source:function(){return api.get.email_source(this.id)},dom:function(e){if(!e)return this.$el;var t={body:"div.a3s",from:"span[email].gD",to:"span[email].g2",to_wrapper:"span.hb",timestamp:"span.g3",star:"div.zd",reply_button:"div[role=button].aaq",menu_button:"div[role=button].aap",details_button:"div[role=button].ajz"};if(!t[e])throw"Dom lookup failed. Unable to find config for '"+e+"'";return this.$el.find(t[e])}});api.dom.thread=function(e){if(!e||!e.hasClass("if"))throw"api.dom.thread called with invalid element/id";this.$el=e;return this};$.extend(api.dom.thread.prototype,{dom:function(e){if(!e)return this.$el;var t={opened_email:"div.adn",subject:"h2.hP",labels:"div.hN"};if(!t[e])throw"Dom lookup failed. Unable to find config for '"+e+"'";return this.$el.find(t[e])}});api.compose.start_compose=function(){var e=$(".T-I.J-J5-Ji.T-I-KE.L3")[0];if(e){var t=document.createEvent("MouseEvents");t.initEvent("mousedown",true,false);e.dispatchEvent(t);var n=document.createEvent("MouseEvents");n.initEvent("mouseup",true,false);e.dispatchEvent(n);return true}return false};return api}