Skip to content

Commit

Permalink
fix issues with tracking images not being caught on reply/fwd's. Hand…
Browse files Browse the repository at this point in the history
…le tracking images with height/width of 0 (mailtrack.io). use latest version of jquery and gmail.js.
  • Loading branch information
Omar Qureshi committed Apr 18, 2015
1 parent e928e2e commit 6329ceb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 67 deletions.
21 changes: 10 additions & 11 deletions bg.js
Original file line number Diff line number Diff line change
@@ -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']);
3 changes: 1 addition & 2 deletions cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "PixelBlock",
"version": "0.0.7",
"version": "0.0.8",
"permissions": [
"*://*.googleusercontent.com/proxy/*", "webRequest", "webRequestBlocking"
],
Expand Down
3 changes: 2 additions & 1 deletion scripts/gmail.min.js

Large diffs are not rendered by default.

105 changes: 53 additions & 52 deletions scripts/main.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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(); } );
Expand All @@ -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 = '<div class="hover-content">';
content += '<div>Blocked <span style="font-weight:bold;text-decoration:underline;">' + imgs.length + '</span> tracking attempt' + plural + '</div>';
content += '<div style="margin-top:8px;"><span style="text-decoration:underline;">Source' + plural + '</span>:&nbsp;';

$.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 += '<a class="tracker-name" href="'+ this.tracker_info.url +'" target="_blank" title="' + this.tracker_info.url + '">' + this.tracker_info.name + '</a>';
}else{
Expand All @@ -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(){
Expand All @@ -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) {
Expand Down

0 comments on commit 6329ceb

Please sign in to comment.