forked from KartikTalwar/gmail.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmail.min.js
1 lines (1 loc) · 16 KB
/
gmail.min.js
1
var Gmail=function(){var api={get:{},observe:{},check:{},tools:{},tracker:{},dom:{}};api.version="0.2.2";api.tracker.globals=GLOBALS;api.tracker.view_data=VIEW_DATA;api.tracker.ik=api.tracker.globals[9];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.dom.inboxes=function(){var e=api.dom.inbox_content();return e.find("[gh=tl]")};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.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.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){if(e.url.act=="fup"||e.url.act=="fuv"||typeof e.body=="object"){return}if(e.method=="POST"&&typeof e.url.act=="string"){}if(e.url.search!=undefined){}var t={tae:"add_to_tasks","rc_^i":"archive",tr:"delete",dm:"delete_message_in_thread",dl:"delete_forever",dc_:"delete_label",dd:"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 n=decodeURIComponent(e.url.act);var r=api.tools.deparam(e.body);var i=typeof r.t=="string"?[r.t]:r.t;var s=null;switch(n){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"dd":case"mt":case"cffm":case"rc_^i":var s=[i,e.url,e.body];break;case"arl":var s=[i,e.url,e.body,e.url.acn];break;case"sd":var s=[i,e.url,r];break;case"tae":case"sm":var s=[e.url,e.body,r];break;case"el":var s=[e.url,e.body,r.ex=="1"];break;case"dm":case"rtr":var s=[r.m,e.url,e.body];break}if(typeof e.url._reqid=="string"&&typeof e.url.th=="string"){var s=[e.url.th,e.url,e.body];if("new_email"in api.tracker.watchdog){api.tracker.watchdog["new_email"].apply(undefined,s)}}if((e.url.view=="cv"||e.url.view=="ad")&&typeof e.url.th=="string"&&typeof e.url.search=="string"&&e.url.rid==undefined){var s=[e.url.th,e.url,e.body];if("open_email"in api.tracker.watchdog){api.tracker.watchdog["open_email"].apply(undefined,s)}}if((e.url.view=="cv"||e.url.view=="ad")&&typeof e.url.th=="object"&&typeof e.url.search=="string"&&e.url.rid!=undefined){var s=[e.url.th,e.url,e.body];if("toggle_threads"in api.tracker.watchdog){api.tracker.watchdog["toggle_threads"].apply(undefined,s)}}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){var s=[e.url.th,e.url,e.body];if("toggle_threads"in api.tracker.watchdog){api.tracker.watchdog["toggle_threads"].apply(undefined,s)}}}if(typeof e.url.SID=="string"&&typeof e.url.zx=="string"&&e.body.indexOf("req0_")!=-1){api.tracker.SID=e.url.SID;var s=[e.url,e.body,r];if("poll"in api.tracker.watchdog){api.tracker.watchdog["poll"].apply(undefined,s)}}if(typeof e.url.ik=="string"&&typeof e.url.search=="string"&&e.body.length==0&&typeof e.url._reqid=="string"){var s=[e.url,e.body,r];if("refresh"in api.tracker.watchdog){api.tracker.watchdog["refresh"].apply(undefined,s)}}if(s!=null){if(t[n]in api.tracker.watchdog){api.tracker.watchdog[t[n]].apply(undefined,s)}}};api.tools.parse_requests=function(e){e.url_raw=e.url;e.url=api.tools.parse_url(e.url);if(typeof api.tracker.events!="object"&&typeof api.tracker.actions!="object"){api.tracker.events=[];api.tracker.actions=[]}api.tracker.events.unshift(e);api.tools.parse_actions(e);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()}};api.tools.xhr_watcher=function(){var e=this;if(!api.tracker.xhr_init){var t=top.document.getElementById("js_frame").contentDocument.defaultView;api.tracker.xhr_init=true;api.tracker.xhr_open=t.XMLHttpRequest.prototype.open;api.tracker.xhr_send=t.XMLHttpRequest.prototype.send;t.XMLHttpRequest.prototype._gjs_open=t.XMLHttpRequest.prototype.open;t.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};t.XMLHttpRequest.prototype._gjs_send=t.XMLHttpRequest.prototype.send;t.XMLHttpRequest.prototype.send=function(e){var t=this._gjs_send.apply(this,arguments);if(this.xhrParams){this.xhrParams.body=e;api.tools.parse_requests(this.xhrParams)}return t}}};api.observe.http_requests=function(){return api.tracker.events};api.observe.actions=function(){return api.tracker.actions};api.observe.on=function(e,t){if(typeof api.tracker.watchdog!="object"){api.tracker.watchdog={}}if(!api.tracker.xhr_init){api.tools.xhr_watcher()}api.tracker.watchdog[e]=t};api.observe.off=function(e){if(e){if("watchdog"in api.tracker){if(e in api.tracker.watchdog){delete api.tracker.watchdog[e]}}}else{var t=top.document.getElementById("js_frame").contentDocument.defaultView;t.XMLHttpRequest.prototype.open=api.tracker.xhr_open;t.XMLHttpRequest.prototype.send=api.tracker.xhr_send;api.tracker.xhr_init=false}};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){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"];var n=null;if($.inArray(e,t)>-1){n=e}if(e.indexOf("label/")==0||e.indexOf("category/")==0||e.indexOf("search/")==0){if(e.split("/").length<3){n=e}}return n};api.tools.infobox=function(e,t){var n=$(".b8.UC");if(n.length>0){var r=n.find(".vh");r.text(e);if(typeof t!=="undefined"){n.css("visibility","visible").fadeTo(t,0,function(){$(this).css("visibility","hidden");$(this).css("opacity","")})}else{n.css("visibility","visible")}}};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]].content_plain=r[8];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]:[];t.threads[r[1]].cc=r[13]!=undefined?r[13][2]:[];t.threads[r[1]].bcc=r[13]!=undefined?r[13][3]:[]}}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.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"en":default:n={inbox:"Inbox",drafts:"Drafts",spam:"Spam",forums:"Forums",updates:"Updates",promotions:"Promotions",social_updates:"Social Updates"};break}return n[e]};return api}