diff --git a/bg.js b/bg.js index 8419112..c0066a0 100644 --- a/bg.js +++ b/bg.js @@ -1,24 +1,23 @@ chrome.webRequest.onBeforeSendHeaders.addListener(function(req){ - var blockingResponse = {}; - // Determine whether to block this image req - var safe = req.url.indexOf('safe-img-pbz') > 0? true:false; - console.log('safe? ' + safe); + var blocking_response = {}; + // Determine whether to block this image request + var safe = req.url.indexOf('safe-img-pbza') > 0? true:false; + //Check if this request came from gmail - var fromGmail = false, headers = req.requestHeaders; + var from_gmail = false, headers = req.requestHeaders; for(var i = 0; i < headers.length; i++) { if(headers[i].name.toLowerCase() == 'referer'){ - if(headers[i].value.indexOf('//mail.google.com/mail') > 0){ - fromGmail = true; + if(headers[i].value.indexOf('//mail.google.com/') > 0){ + from_gmail = true; break; } } } - if(req.type == 'image' && !safe && fromGmail){ - console.log(JSON.stringify(req)); - blockingResponse.cancel = true; + if(req.type == 'image' && !safe && from_gmail){ + blocking_response.cancel = true; } - return blockingResponse; + return blocking_response; }, {urls: [ "*://*.googleusercontent.com/proxy/*" ]},['requestHeaders','blocking']); diff --git a/cs.js b/cs.js index 74e8f0a..40bc803 100644 --- a/cs.js +++ b/cs.js @@ -2,14 +2,13 @@ window.onload = function () { // jquery var jq = document.createElement('script'); - jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"; + jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"; document.getElementsByTagName('body')[0].appendChild(jq); // gmail.js var gmsrc = document.createElement('script'); gmsrc.src = chrome.extension.getURL('scripts/gmail.min.js'); document.getElementsByTagName('body')[0].appendChild(gmsrc); - console.log("Gmail.js ready to go!"); // main.js var sm = document.createElement('script'); diff --git a/manifest.json b/manifest.json index 8b42c8f..146f84e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "PixelBlock", - "version": "0.0.7", + "version": "0.0.8", "permissions": [ "*://*.googleusercontent.com/proxy/*", "webRequest", "webRequestBlocking" ], diff --git a/scripts/gmail.min.js b/scripts/gmail.min.js index 91252e8..7e59b42 100644 --- a/scripts/gmail.min.js +++ b/scripts/gmail.min.js @@ -1 +1,2 @@ -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;t0};api.dom.email_contents=function(){var e=$(".ii.gt");var t=[];for(var n=0;n0};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;i50){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;r0){$.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} \ No newline at end of file +var Gmail=function(localJQuery){var $;"undefined"!=typeof localJQuery?$=localJQuery:"undefined"!=typeof jQuery&&($=jQuery);var api={get:{},observe:{},check:{},tools:{},tracker:{},dom:{},chat:{},compose:{}};return api.version="0.4",api.tracker.globals=GLOBALS,api.tracker.view_data="undefined"!=typeof VIEW_DATA?VIEW_DATA:[],api.tracker.ik=api.tracker.globals[9],api.tracker.hangouts=void 0,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],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.get.localization=function(){var e=function(e){if(!e||"string"!=typeof e||e.length<2)return!1;var t=e.slice(0,2);return t.toLowerCase()===t},t=api.tracker.globals,a=t[17]&&t[17][8]&&t[17][8][8];return e(a)?a:(a=t[17]&&t[17][9]&&t[17][9][8],e(a)?a:null)},api.check.is_thread=function(){var e=$(".nH .if").children(":eq(1)").children().children(":eq(1)").children(),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(),t=e.find("[gh=tl]"),a=!1;return t.each(function(){$(this).hasClass("aia")&&(a=!0)}),a},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(),t=e.find("[gh=tl]").find(".nn");return 0==t.length},api.check.is_vertical_split=function(){return 0==api.check.is_horizontal_split()},api.check.is_tabbed_inbox=function(){return 1==$(".aKh").length},api.check.is_right_side_chat=function(){return":wf"==$(".ApVoH")[0].getAttribute("aria-labelledby")},api.check.is_google_apps_user=function(){var e=api.get.user_email();return-1==e.indexOf("gmail.com",e.length-"gmail.com".length)},api.get.storage_info=function(){var e=$(".md.mj").find("div")[0],t=$(e).find("span")[0].text,a=$(e).find("span")[1].text,r=100*parseFloat(t.replace(/[^0-9\.]/g,""))/parseFloat(a.replace(/[^0-9\.]/g,""));return{used:t,total:a,percent:Math.floor(r)}},api.dom.inboxes=function(){var e=api.dom.inbox_content();return e.find("[gh=tl]")},api.dom.email_subject=function(){for(var e=$(".hP"),t=0;t0},api.dom.email_contents=function(){for(var e=$(".ii.gt"),t=[],a=0;a0&&t[r].offsetHeight>0;"undefined"!=i&&void 0!=i&&n&&"true"!=o&&a.push(i)}e=a[0].substring(1,a[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 1==$("#rapportive-sidebar").length},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(){for(var e="bx_hs",t=void 0,a=!0,r=api.tracker.globals[17][5][1],i=0;i0&&-1!=e[0].text.indexOf("(")?parseInt(e[0].text.replace(/[^0-9]/g,"")):0},api.get.unread_draft_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("drafts")+"']");return e.length>0&&-1!=e[0].text.indexOf("(")?parseInt(e[0].text.replace(/[^0-9]/g,"")):0},api.get.unread_spam_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("spam")+"']");return e.length>0&&-1!=e[0].text.indexOf("(")?parseInt(e[0].text.replace(/[^0-9]/g,"")):0},api.get.unread_forum_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("forums")+"']");return e.length>0&&-1!=e[0].text.indexOf("(")?parseInt(e[0].text.replace(/[^0-9]/g,"")):0},api.get.unread_update_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("updates")+"']");return e.length>0&&-1!=e[0].text.indexOf("(")?parseInt(e[0].text.replace(/[^0-9]/g,"")):0},api.get.unread_promotion_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("promotions")+"']");return e.length>0&&-1!=e[0].text.indexOf("(")?parseInt(e[0].text.replace(/[^0-9]/g,"")):0},api.get.unread_social_emails=function(){var e=$("div[role=navigation]").find("[title*='"+api.tools.i18n("social_updates")+"']");return e.length>0&&-1!=e[0].text.indexOf("(")?parseInt(e[0].text.replace(/[^0-9]/g,"")):0},api.get.beta=function(){var e={new_nav_bar:0==$("#gbz").length};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.error=function(e){if(!console)throw e;console.error(e)},api.tools.parse_url=function(e){for(var t,a=/[?&]([^=#]+)=([^&#]*)/g,r={};t=a.exec(e);)r[t[1]]=t[2];return r},api.tools.sleep=function(e){for(var t=(new Date).getTime();;)if((new Date).getTime()-t>e)break},api.tools.multitry=function(e,t,a,r,i,o){if(void 0!=i&&i>=t)return o;var i=void 0==i?0:i,n=a();return r(n)?n:(api.tools.sleep(e),void api.tools.multitry(e,t,a,r,i+1,n))},api.tools.deparam=function(e,t){var a=function(e,t){var a=[];for(i=0;i=c;c++)s=""===d[c]?l.length:d[c],l=l[s]=p>c?l[s]||(d[c+1]&&isNaN(d[c+1])?{}:[]):a;else r(o[s])?o[s].push(a):o[s]=void 0!==o[s]?[o[s],a]:a;else s&&(o[s]=t?void 0:"")}),o},api.tools.parse_actions=function(e){if("fup"==e.url.act||"fuv"==e.url.act||e.body_is_object)return e.body_is_object&&api.observe.bound("upload_attachment")?{upload_attachment:[e.body_params]}:!1;void 0!=e.url.search;var t={},a={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"};"string"==typeof e.url.ik&&(api.tracker.ik=e.url.ik),"string"==typeof e.url.rid&&-1!=e.url.rid.indexOf("mail")&&(api.tracker.rid=e.url.rid);var r=decodeURIComponent(e.url.act),i=e.body_params,o="string"==typeof i.t?[i.t]:i.t,n=null;switch(r){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":n=[o,e.url,e.body];break;case"arl":n=[o,e.url,e.body,e.url.acn];break;case"sd":n=[o,e.url,i];break;case"tae":case"sm":n=[e.url,e.body,i];break;case"el":n=[e.url,e.body,"1"==i.ex];break;case"dm":case"rtr":case"mo":n=[i.m,e.url,e.body]}return"string"==typeof e.url._reqid&&"string"==typeof e.url.th&&(n=[e.url.th,e.url,e.body],api.observe.bound("new_email")&&(t.new_email=n)),"cv"!=e.url.view&&"ad"!=e.url.view||"string"!=typeof e.url.th||"string"!=typeof e.url.search||void 0!=e.url.rid||(n=[e.url.th,e.url,e.body],api.observe.bound("open_email")&&(t.open_email=n)),"cv"!=e.url.view&&"ad"!=e.url.view||"object"!=typeof e.url.th||"string"!=typeof e.url.search||void 0==e.url.rid||(n=[e.url.th,e.url,e.body],api.observe.bound("toggle_threads")&&(t.toggle_threads=n)),"cv"!=e.url.view&&"ad"!=e.url.view||"string"!=typeof e.url.th||"string"!=typeof e.url.search||void 0==e.url.rid||void 0!=e.url.msgs&&(n=[e.url.th,e.url,e.body],api.observe.bound("toggle_threads")&&(t.toggle_threads=n)),"string"==typeof e.url.SID&&"string"==typeof e.url.zx&&-1!=e.body.indexOf("req0_")&&(api.tracker.SID=e.url.SID,n=[e.url,e.body,i],api.observe.bound("poll")&&(t.poll=n)),"string"==typeof e.url.ik&&"string"==typeof e.url.search&&0==e.body.length&&"string"==typeof e.url._reqid&&(n=[e.url,e.body,i],api.observe.bound("refresh")&&(t.refresh=n)),n&&a[r]&&api.observe.bound(a[r])&&(t[a[r]]=n),"POST"!=e.method||"string"!=typeof e.url.SID&&"string"!=typeof e.url.ik&&"string"!=typeof e.url.act||(t.http_event=[e]),t},api.tools.parse_response=function(response){var parsedResponse=[],data,dataLength,endIndex,realData;try{for(response=response.replace(/\n/g," "),response=response.substring(response.indexOf("'")+1,response.length);response.replace(/\s/g,"").length>1;)dataLength=response.substring(0,response.indexOf("[")).replace(/\s/g,""),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),"object"==typeof e.body?(e.body_params=e.body,e.body_is_object=!0):e.body_params=api.tools.deparam(e.body),"object"!=typeof api.tracker.events&&"object"!=typeof api.tracker.actions&&(api.tracker.events=[],api.tracker.actions=[]),api.tracker.events.unshift(e);var a=api.tools.parse_actions(e,t);return"POST"==e.method&&"string"==typeof e.url.act&&api.tracker.actions.unshift(e),api.tracker.events.length>50&&api.tracker.events.pop(),api.tracker.actions.length>10&&api.tracker.actions.pop(),a},api.tools.xhr_watcher=function(){if(!api.tracker.xhr_init){var e=top.document.getElementById("js_frame").contentDocument.defaultView;api.tracker.xhr_init=!0,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){var a=this._gjs_open.apply(this,arguments);return this.xhrParams={method:e.toString(),url:t.toString()},a},e.XMLHttpRequest.prototype._gjs_send=e.XMLHttpRequest.prototype.send,e.XMLHttpRequest.prototype.send=function(e){var t=!1;if(this.xhrParams&&(this.xhrParams.body=e,t=api.tools.parse_requests(this.xhrParams,this)),api.observe.trigger("before",t,this)&&(e=arguments[0]=this.xhrParams.body_is_object?this.xhrParams.body_params:$.param(this.xhrParams.body_params,!0)),api.observe.bound(t,"after")){var a=this.onreadystatechange,r=this;this.onreadystatechange=function(e){this.readyState===this.DONE&&(r.xhrResponse=api.tools.parse_response(e.target.responseText),api.observe.trigger("after",t,r)),a&&a.apply(this,arguments)}}var i=this._gjs_send.apply(this,arguments);return api.observe.trigger("on",t,this),i}}},api.observe.http_requests=function(){return api.tracker.events},api.observe.actions=function(){return api.tracker.actions},api.observe.bind=function(e,t,a){"object"!=typeof api.tracker.watchdog&&(api.tracker.watchdog={before:{},on:{},after:{},dom:{}},api.tracker.bound={}),"object"!=typeof api.tracker.watchdog[e]&&api.tools.error("api.observe.bind called with invalid type: "+e),"dom"==e||api.tracker.xhr_init||api.tools.xhr_watcher(),"object"!=typeof api.tracker.watchdog[e][t]&&(api.tracker.watchdog[e][t]=[]),api.tracker.watchdog[e][t].push(a),api.tracker.bound[t]="undefined"==typeof api.tracker.bound[t]?1:api.tracker.bound[t]+1,api.tracker.bound[e]="undefined"==typeof api.tracker.bound[e]?1:api.tracker.bound[e]+1},api.observe.on=function(e,t,a){return api.observe.on_dom(e,t)?!0:(api.observe.bind("on",e,t),void(a&&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("object"!=typeof api.tracker.watchdog)return!1;if(e){if("object"==typeof e){var a=!1;return $.each(e,function(e){"object"==typeof api.tracker.watchdog[t][e]&&(a=!0)}),a}return t?"object"==typeof api.tracker.watchdog[t][e]:api.tracker.bound[e]>0}return t?api.tracker.bound[t]>0:void api.tools.error("api.observe.bound called with invalid args")},api.observe.off=function(e,t){if("object"!=typeof api.tracker.watchdog)return!0;if(!t&&!e){var a=top.document.getElementById("js_frame").contentDocument.defaultView;a.XMLHttpRequest.prototype.open=api.tracker.xhr_open,a.XMLHttpRequest.prototype.send=api.tracker.xhr_send,api.tracker.xhr_init=!1}var r=t?[t]:["before","on","after","dom"];$.each(r,function(t,a){return"object"!=typeof api.tracker.watchdog[a]?!0:void(e?"object"==typeof api.tracker.watchdog[a][e]&&(api.tracker.bound[e]-=api.tracker.watchdog[a][e].length,api.tracker.bound[a]-=api.tracker.watchdog[a][e].length,delete api.tracker.watchdog[a][e]):$.each(api.tracker.watchdog[a],function(e){"object"==typeof api.tracker.watchdog[a][e]&&(api.tracker.bound[e]-=api.tracker.watchdog[a][e].length,api.tracker.bound[a]-=api.tracker.watchdog[a][e].length,delete api.tracker.watchdog[a][e])}))})},api.observe.trigger=function(e,t,a){if(!t)return!1;var r=!1;return $.each(t,function(t,i){i=$.extend([],i),"after"==e&&i.push(a.xhrResponse),i.push(a),api.observe.bound(t,e)&&(r=!0,$.each(api.tracker.watchdog[e][t],function(e,t){t.apply(void 0,i)}))}),r},api.observe.trigger_dom=function(e,t,a){a||(a=function(e,t){t(e)}),api.tracker.watchdog.dom[e]&&$.each(api.tracker.watchdog.dom[e],function(e,r){a(t,r)})},api.observe.initialize_dom_observers=function(){api.tracker.dom_observer_init=!0,api.tracker.supported_observers=["view_thread","view_email","load_email_menu","recipient_change","compose"],api.tracker.dom_observers={view_thread:{"class":["Bu","nH"],sub_selector:"div.if",handler:function(e,t){e=new api.dom.thread(e),t(e);var a=e.dom("opened_email");a.length&&api.observe.trigger_dom("view_email",a,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){"object"!=typeof api.tracker.recipient_matches&&(api.tracker.recipient_matches=[]),api.tracker.recipient_matches.push(e),setTimeout(function(){if(api.tracker.recipient_matches.length){var e=new api.dom.compose(api.tracker.recipient_matches[0].closest("div.M9")),a=e.recipients();t(e,a,api.tracker.recipient_matches),api.tracker.recipient_matches=[]}},100)}},compose:{"class":"An",handler:function(e,t){if(e=e.closest("div.M9"),e.length){e=new api.dom.compose(e);var a;a=e.is_inline()?0==e.find("input[name=subject]").val().indexOf("Fw")?"forward":"reply":"compose",t(e,a)}}}},api.tracker.custom_supported_observers&&($.merge(api.tracker.supported_observers,api.tracker.custom_supported_observers),$.extend(!0,api.tracker.dom_observers,api.tracker.custom_dom_observers)),api.tracker.dom_observer_map={},$.each(api.tracker.dom_observers,function(e,t){$.isArray(t.class)||(t.class=[t.class]),$.each(t.class,function(t,a){api.tracker.dom_observer_map[a]=e})})},api.observe.register=function(e,t,a){api.tracker.dom_observer_init&&api.tools.error("Error: Please register all custom DOM observers before binding handlers using gmail.observe.on etc"),api.tracker.custom_supported_observers||(api.tracker.custom_supported_observers=[],api.tracker.custom_dom_observers={});var r={};"object"!=typeof t||$.isArray(t)?r["class"]=t:$.each(["class","selector","sub_selector","handler"],function(e,a){t[a]&&(r[a]=t[a])}),api.tracker.custom_supported_observers.push(e),a?(api.tracker.custom_dom_observers[a]||(api.tracker.custom_dom_observers[a]={sub_observers:{}}),api.tracker.custom_dom_observers[a].sub_observers[e]=r):api.tracker.custom_dom_observers[e]=r},api.observe.on_dom=function(e,t){if(api.tracker.dom_observer_init||api.observe.initialize_dom_observers(),$.inArray(e,api.tracker.supported_observers)>-1)return api.tracker.observing_dom||(api.tracker.observing_dom=!0,$(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),!0;if("load"==e){if(api.dom.inbox_content().length)return t();var a=0,r=200,i=50,o=setInterval(function(){var e=api.dom.inbox_content().length;return e>0?(clearInterval(o),t()):void(++a>i&&(clearInterval(o),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!0}},api.tools.insertion_observer=function(e,t,a){if(api.tracker.dom_observer_map){var r=e.className.trim().split(/\s+/);r.length||r.push(""),$.each(r,function(r,i){var o=a[i];if(o&&api.tracker.watchdog.dom[o]){var n=$(e),s=t[o];if(s.selector&&!n.is(s.selector))return;if(s.sub_selector&&(n=n.find(s.sub_selector)),n.length){var l=s.handler?s.handler:function(e,t){t(e)};if(api.observe.trigger_dom(o,n,l),s.sub_observers){var c={};$.each(s.sub_observers,function(e,t){c[t.class]=e}),n.bind("DOMNodeInserted",function(e){api.tools.insertion_observer(e.target,s.sub_observers,c,"SUB ")})}}}})}},api.tools.make_request=function(e,t){var t=void 0==typeof t||null==typeof t?"GET":t,a=$.ajax({type:t,url:encodeURI(e),async:!1});return a.responseText},api.tools.parse_view_data=function(e){for(var t=[],a=[],r=0;r0&&$.merge(emails,cdata)}return emails},api.get.selected_emails_data=function(){var e=[];if(api.check.is_inside_email())e.push(api.get.email_data());else if($('[gh="tl"] div[role="checkbox"][aria-checked="true"]').length){var t=null,a=api.get.visible_emails();$('[gh="tl"] div[role="checkbox"]').each(function(r){"true"==$(this).attr("aria-checked")&&(t=api.get.email_data(a[r].id),e.push(t))})}return e},api.get.current_page=function(){var e=window.location.hash.split("#").pop(),t=["sent","inbox","starred","drafts","imp","chats","all","spam","trash","settings"],a=null;return $.inArray(e,t)>-1&&(a=e),(0==e.indexOf("label/")||0==e.indexOf("category/")||0==e.indexOf("search/")||0==e.indexOf("settings/"))&&e.split("/").length<3&&(a=e),a},api.tools.infobox=function(e,t,a){var r=$(".b8.UC");if(r.length>0){r.stop(!1,!0);var i=r.find(".vh");if(a?i.html(e):i.text(e),"undefined"!=typeof t){var o=r.attr("style");r.removeAttr("style").fadeTo(t,0,function(){$(this).attr("style",o)})}else r.removeAttr("style")}},api.tools.rerender=function(e){var t,a=window.location.href,r=window.location.hash;t=-1!==r.indexOf("/")?a.replace(/#.*?\//,"#/"):a.replace(/#.*/,"#"),window.location.replace(t),setTimeout(function(){window.location.replace(a),window.history.back(),e&&e()},0)},api.tools.get_reply_to=function(e){var t=void 0!=e?e[4]:[];return 0!==t.length?api.tools.extract_email_address(t[0]):null},api.tools.parse_email_data=function(e){var t={};for(i in e){var a=e[i];if("cs"==a[0]&&(t.thread_id=a[1],t.first_email=a[8][0],t.last_email=a[2],t.total_emails=a[3],t.total_threads=a[8],t.people_involved=a[15],t.subject=a[23]),"ms"==a[0]){void 0==t.threads&&(t.threads={}),t.threads[a[1]]={},t.threads[a[1]].is_deleted=void 0==a[13],t.threads[a[1]].reply_to_id=a[2],t.threads[a[1]].from=a[5],t.threads[a[1]].from_email=a[6],t.threads[a[1]].timestamp=a[7],t.threads[a[1]].datetime=a[24],t.threads[a[1]].attachments=a[21].split(","),t.threads[a[1]].subject=a[12],t.threads[a[1]].content_html=void 0!=a[13]?a[13][6]:a[8],t.threads[a[1]].to=void 0!=a[13]?a[13][1]:void 0!=a[37]?a[37][1]:[],t.threads[a[1]].cc=void 0!=a[13]?a[13][2]:[],t.threads[a[1]].bcc=void 0!=a[13]?a[13][3]:[],t.threads[a[1]].reply_to=api.tools.get_reply_to(a[13]);try{t.threads[a[1]].content_plain=void 0!=a[13]?$(a[13][6]).text():a[8]}catch(r){t.threads[a[1]].content_plain=void 0!=a[13]?a[13][6]:a[8]}}}return t},api.get.email_data=function(email_id){if(api.check.is_inside_email()&&void 0==email_id&&(email_id=api.get.email_id()),void 0!=email_id){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=mbox",get_data=api.tools.make_request(url);return 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],api.tools.parse_email_data(api.tracker.email_data)}return{}},api.get.email_source=function(e){if(api.check.is_inside_email()&&void 0==e&&(e=api.get.email_id()),void 0!=e){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(),t={};if(api.check.is_conversation_view()){t=e;var a=t.threads,r=t.total_threads,i=window.location.hash.split("#")[1]||"",o=0===i.indexOf("trash");for(id in a){var n=a[id],s=o?n.is_deleted:!n.is_deleted;s||(delete a[id],r.splice(r.indexOf(id),1),t.total_emails--)}}else for(id in e.threads){var l=$('.ii.gt[class*="'+id+'"]');if(l.length>0){var n=e.threads[id];t.first_email=id,t.last_email=id,t.subject=e.subject,t.threads={},t.threads[id]=n,t.total_emails=1,t.total_threads=[id],t.people_involved=[],t.people_involved.push([n.from,n.from_email]),n.to.forEach(function(e){var a=api.tools.extract_email_address(e),r=api.tools.extract_name(e.replace(a,""))||"";t.people_involved.push([r,a])});break}}return t},api.check.is_conversation_view=function(){for(var e="bx_vmb",t=void 0,a=api.tracker.globals[17][5][1],r=0;r .J-J5-Ji").append(i)},api.tools.add_modal_window=function(e,t,a,r,i){var o=function(){$("#gmailJsModalBackground").remove(),$("#gmailJsModalWindow").remove()};i=i||o,r=r||o;var n=$(document.createElement("div"));n.attr("id","gmailJsModalBackground"),n.attr("class","Kj-JD-Jh"),n.attr("aria-hidden","true"),n.attr("style","opacity:0.75;width:100%;height:100%;");var s=$(document.createElement("div"));s.attr("id","gmailJsModalWindow"),s.attr("class","Kj-JD"),s.attr("tabindex","0"),s.attr("role","alertdialog"),s.attr("aria-labelledby","gmailJsModalWindowTitle"),s.attr("style","left:50%;top:50%;opacity:1;");var l=$(document.createElement("div"));l.attr("class","Kj-JD-K7 Kj-JD-K7-GIHV4");var c=$(document.createElement("span"));c.attr("id","gmailJsModalWindowTitle"),c.attr("class","Kj-JD-K7-K0"),c.attr("role","heading"),c.html(e);var d=$(document.createElement("span"));d.attr("id","gmailJsModalWindowClose"),d.attr("class","Kj-JD-K7-Jq"),d.attr("role","button"),d.attr("tabindex","0"),d.attr("aria-label","Close"),d.click(i),l.append(c),l.append(d);var p=$(document.createElement("div"));p.attr("id","gmailJsModalWindowContent"),p.attr("class","Kj-JD-Jz"),p.html(t);var u=$(document.createElement("div"));u.attr("class","Kj-JD-Jl");var m=$(document.createElement("button"));m.attr("id","gmailJsModalWindowOk"),m.attr("class","J-at1-auR J-at1-atl"),m.attr("name","ok"),m.text("OK"),m.click(a);var h=$(document.createElement("button"));h.attr("id","gmailJsModalWindowCancel"),h.attr("name","cancel"),h.text("Cancel"),h.click(r),u.append(m),u.append(h),s.append(l),s.append(p),s.append(u),$(document.body).append(n),$(document.body).append(s);var f=function(){s.css({top:($(window).height()-s.outerHeight())/2,left:($(window).width()-s.outerWidth())/2})};f(),$(window).resize(f)},api.chat.is_hangouts=function(){if(void 0!=api.tracker.hangouts)return api.tracker.hangouts;var e=$(".dw");if(e.length>1)throw"Figuring out is hangouts - more than one dw classes found";if(0==e.length)throw"Figuring out is hangouts - no dw classes found";var t=e[0],a=$(".nH.aJl.nn",t);if(a.length>0)return api.tracker.hangouts=!0,!0;var a=$(".nH.nn",t);return a.length>2?(api.tracker.hangouts=!1,!1):void 0},api.dom.composes=function(){return objs=[],$("div.M9").each(function(e,t){objs.push(new api.dom.compose(t))}),objs},api.dom.compose=function(e){return e=$(e),e&&(e.hasClass("M9")||e.hasClass("AD"))||api.tools.error("api.dom.compose called with invalid element"),this.$el=e,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){"object"!=typeof e&&(e={});var t=e.type?"[name="+e.type+"]":"",a=e.flat?[]:{};return this.$el.find(".GS input[type=hidden]"+t).each(function(t,r){e.flat?a.push(r.value):(a[r.name]||(a[r.name]=[]),a[r.name].push(r.value))}),a},to:function(){return this.recipients({type:"to",flat:!0})},cc:function(){return this.recipients({type:"cc",flat:!0})},bcc:function(){return this.recipients({type:"bcc",flat:!0})},subject:function(e){this.dom("subjectbox");return e&&this.dom("all_subjects").val(e),e=this.dom("subjectbox").val(),e?e:this.dom("subject").val()},body:function(e){var t=this.dom("body");return e&&t.html(e),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]",all_subjects:"input[name=subjectbox], input[name=subject]",body:"div[contenteditable=true]",reply:"M9",forward:"M9"};return t[e]||api.tools.error("Dom lookup failed. Unable to find config for '"+e+"'",t,e,t[e]),this.$el.find(t[e])}}),api.dom.email=function(e){return"string"==typeof e?(this.id=e,this.id_element=$("div.ii.gt.m"+this.id),e=this.id_element.closest("div.adn")):e=$(e),e&&e.hasClass("adn")||api.tools.error("api.dom.email called with invalid element/id"),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,this},$.extend(api.dom.email.prototype,{body:function(e){var t=this.dom("body");return e&&t.html(e),t.html()},from:function(e,t){var a=this.dom("from");return e&&a.attr("email",e),t&&(a.attr("name",t),a.html(t)),{email:a.attr("email"),name:a.attr("name"),el:a}},to:function(e){if(e){$.isArray(e)||(e=[e]);var t=[];$.each(e,function(e,a){t.push($("").attr({dir:"ltr",email:a.email,name:a.name}).addClass("g2").html(a.name).wrap("

").parent().html())}),this.dom("to_wrapper").html("to "+t.join(", "))}var a=new Array;return this.dom("to").each(function(){el=$(this),a.push({email:el.attr("email"),name:el.attr("name"),el:el})}),a},data:function(){if("object"!=typeof api.dom.email_cache&&(api.dom.email_cache={}),!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"}; +return t[e]||api.tools.error("Dom lookup failed. Unable to find config for '"+e+"'"),this.$el.find(t[e])}}),api.dom.thread=function(e){return e&&e.hasClass("if")||api.tools.error("api.dom.thread called with invalid element/id"),this.$el=e,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"};return t[e]||api.tools.error("Dom lookup failed. Unable to find config for '"+e+"'"),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",!0,!1),e.dispatchEvent(t);var a=document.createEvent("MouseEvents");return a.initEvent("mouseup",!0,!1),e.dispatchEvent(a),!0}return!1},api}; \ No newline at end of file diff --git a/scripts/main.js b/scripts/main.js index 9bb9388..3c602b4 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,47 +1,48 @@ - - +/** + * + */ var pixelblock = (function(){ - var blacklist = [{name:'Signals', pattern:'t.signaux', url:'http://getsignals.com'}, - {name:'Signals', pattern:'t.senaldos.com', url:'http://getsignals.com'}, - {name:'Banana Tag', pattern:'bl-1.com', url:'http://bananatag.com'}, - {name:'Boomerang', pattern:'mailstat.us/tr', url:'http://boomeranggmail.com'}, - {name:'Yesware', pattern:'app.yesware.com', url:'http://yesware.com'}, - {name:'Yesware', pattern:'t.yesware.com', url:'http://yesware.com'}, - {name:'Streak', pattern:'mailfoogae.appspot.com', url:'http://streak.com'}, - {name:'LaunchBit', pattern:'launchbit.com/taz-pixel',url:'http://launchbit.com'}, - {name:'MailChimp', pattern:'list-manage.com/track', url:'http://mailchimp.com'}, - {name:'Postmark', pattern:'cmail1.com/t', url:'http://postmarkapp.com'}, - {name:'iContact', pattern:'click.icptrack.com/icp/',url:'http://icontact.com'}, - {name:'Infusionsoft', pattern:'infusionsoft.com/app/emailOpened', url:'http://infusionsoft.com'}, - {name:'Intercom', pattern:'via.intercom.io/o', url:'http://intercom.io'}, - {name:'Mandrill', pattern:'mandrillapp.com/track', url:'http://mandrillapp.com'}, - {name:'Hubspot', pattern:'t.hsms06.com', url: 'http://hubspot.com'}, - {name:'RJ Metrics', pattern:'go.rjmetrics.com', url:'http://rjmetrics.com'}, - {name:'Mixpanel', pattern:'api.mixpanel.com/track', url:'http://mixpanel.com'}, - {name:'Front App', pattern:'web.frontapp.com/api', url:'http://frontapp.com'} - ]; - - var gmail = null, - safe_pattern = '?safe-img-pbz#', + var gmail = null, + safe_pattern = '?safe-img-pbza#', proxy_pattern = 'googleusercontent.com/proxy'; + var blacklist = [{name:'Signals', pattern:'t.signaux', url:'http://getsignals.com'}, + {name:'Signals', pattern:'t.senaldos.com', url:'http://getsignals.com'}, + {name:'Banana Tag', pattern:'bl-1.com', url:'http://bananatag.com'}, + {name:'Boomerang', pattern:'mailstat.us/tr', url:'http://boomeranggmail.com'}, + {name:'Yesware', pattern:'app.yesware.com', url:'http://yesware.com'}, + {name:'Yesware', pattern:'t.yesware.com', url:'http://yesware.com'}, + {name:'Streak', pattern:'mailfoogae.appspot.com', url:'http://streak.com'}, + {name:'LaunchBit', pattern:'launchbit.com/taz-pixel',url:'http://launchbit.com'}, + {name:'MailChimp', pattern:'list-manage.com/track', url:'http://mailchimp.com'}, + {name:'Postmark', pattern:'cmail1.com/t', url:'http://postmarkapp.com'}, + {name:'iContact', pattern:'click.icptrack.com/icp/',url:'http://icontact.com'}, + {name:'Infusionsoft', pattern:'infusionsoft.com/app/emailOpened', url:'http://infusionsoft.com'}, + {name:'Intercom', pattern:'via.intercom.io/o', url:'http://intercom.io'}, + {name:'Mandrill', pattern:'mandrillapp.com/track', url:'http://mandrillapp.com'}, + {name:'Hubspot', pattern:'t.hsms06.com', url: 'http://hubspot.com'}, + {name:'RJ Metrics', pattern:'go.rjmetrics.com', url:'http://rjmetrics.com'}, + {name:'Mixpanel', pattern:'api.mixpanel.com/track', url:'http://mixpanel.com'}, + {name:'Front App', pattern:'web.frontapp.com/api', url:'http://frontapp.com'}, + {name:'Mailtrack.io', pattern:'mailtrack.io/trace', url:'http://mailtrack.io'}]; + /* * */ - var isBlacklisted = function(img){ + var is_blacklisted = function(img){ var blacklisted = false; // run img src's against our blacklist - for(var x = 0; x < blacklist.length; x ++){ - if(img.src.indexOf(blacklist[x].pattern) > 0) { - img.tracker_info = blacklist[x]; + $.each(blacklist, function() { + if(img.src.indexOf(this.pattern) > 0) { + img.tracker_info = this; blacklisted = true; } - } + }); - // block all images left over that are 1 x 1 (regardless) - if(!blacklisted && $(img).width() == 1 && $(img).height() == 1){ + // block all images left over that are 1 x 1 (or less, regardless) + if(!blacklisted && $(img).width() <= 1 && $(img).height() <= 1){ img.tracker_info = {pattern:'', name:'Unknown', url:''}; blacklisted = true; } @@ -52,22 +53,22 @@ var pixelblock = (function(){ } /* - * Whitelist an img, i.e. let it display/load + * Whitelist an image, i.e. let it display/load */ - var whitelistImg = function(img){ + var whitelist_image = function(img){ if(img.src.indexOf(safe_pattern) == -1) img.src = img.src.replace('#', safe_pattern); } /* * */ - var showTrackingEye = function(email){ - var tracking_imgs = $(email).find("img[tracker='true']"); + var show_tracking_eye = function(email){ + var tracking_images = $(email).find("img[tracker='true']"); - if(tracking_imgs.length > 0){ + if(tracking_images.length > 0){ // Add the red eye var eye = $('#red-eye').clone(); - var content = getPopoverHeader(tracking_imgs); + var content = get_popover_content(tracking_images); $(eye).popover({trigger:'click',placement:'bottom', content:content, html:true}); $(eye).click( function(e){ e.stopPropagation(); } ); @@ -81,16 +82,16 @@ var pixelblock = (function(){ /* * */ - var getPopoverHeader = function(imgs){ - var plural = imgs.length > 1? 's':''; + var get_popover_content = function(imgs){ + var plural = imgs.length > 1 ? 's':''; var content = '

'; content += '
Blocked ' + imgs.length + ' tracking attempt' + plural + '
'; content += '
Source' + plural + ': '; - + $.each(imgs, function(index){ - var url = cleanURL(this.src); + var url = clean_url(this.src); if(index > 0) content += ', '; - + if(this.tracker_info.url != ''){ content += '' + this.tracker_info.name + ''; }else{ @@ -105,39 +106,39 @@ var pixelblock = (function(){ /* * */ - var cleanURL = function(url){ + var clean_url = function(url){ if(url == '' || url.indexOf('#') == -1) return url; return url.substring(url.indexOf('#')+1); } - var scanImgs = function(){ + var scan_images = function(){ var body = gmail.dom.email_body(); var emails = $(body[0]).find('div.h7[processed!="true"]'); // go through all open emails on screen for(var x = 0; x < emails.length; x++){ - var email = emails[x], trackingImgFound = false; + var email = emails[x], tracking_image_found = false; // loop over all images in this email $("img[src]", email).each(function(){ var src = this.src; if(src.indexOf(proxy_pattern) > 0 && src.indexOf(safe_pattern) == -1){ - if(isBlacklisted(this)){ + if(is_blacklisted(this)){ this.setAttribute('tracker', 'true'); - trackingImgFound = true; + tracking_image_found = true; }else{ - whitelistImg(this); + whitelist_image(this); } } }); // show 'eye' - if(trackingImgFound) showTrackingEye(email); + if(tracking_image_found) show_tracking_eye(email); // Handle no images mode if($("div.ado", email).length == 0) email.setAttribute('processed', 'true'); } - setTimeout(scanImgs, 100); + setTimeout(scan_images, 100); } var init = function(){ @@ -148,13 +149,13 @@ var pixelblock = (function(){ } var start = function(){ - setTimeout(scanImgs, 350); + setTimeout(scan_images, 450); } return {init:init, start:start}; })(); -// check if jquery loaded/init'd +// check if jquery loaded & initialized var checkLoaded = function() { if(window.jQuery) { $.fn.onAvailable = function(e) {