forked from amanjain/Track-Me-Not
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
138 lines (125 loc) · 4.24 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* This file is part of 'Track Me Not',
* Copyright (C) 2015-Today Aman Kumar Jain
*
* 'Track Me Not' is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 'Track Me Not' is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'Track Me Not'. If not, see <http://www.gnu.org/licenses/>.
*/
(function(){
'use strict';
/*
* List of trackers, must have name, url and trackingPattern
* IMPROVEMENT: Need to keep tracker's definations externally.
*/
var trackers = [{
'name': 'Amazon\'s Tracking Pixel',
'url': 'http://amazon.com/',
'trackingPattern': /www\.amazon\.(in|com)\/gp\/r\.html\?R\=.*transp\.gif/
}, {
'name': 'bananatag',
'url': 'http://bananatag.com/',
'trackingPattern': /bl\-1\.com\//
}, {
'name': 'ContactMonkey',
'url': 'https://contactmonkey.com/',
'trackingPattern': /contactmonkey\.com\/api\/v1\/tracker/
}, {
'name': 'Dropbox\'s Tracking Pixel',
'url': 'https://www.dropbox.com/',
'trackingPattern': /www\.dropbox\.com\/l\/((?!\/).)*$/
}, {
'name': 'Dyn',
'url': 'https://dyn.com/',
'trackingPattern': /trk\.email\.dynect\.net\/trk.php/
}, {
'name': 'Facebook\'s Tracking Pixel',
'url': 'https://www.facebook.com/',
'trackingPattern': /www\.facebook\.com\/email_open_log_pic\.php/
}, {
'name': 'Flipkart\'s Tracking Pixel',
'url': 'https://flipkart.com/',
'trackingPattern': /www\.flipkart\.com\/ch.php.*=openImg/
}, {
'name': 'Linkedin\'s Tracking Pixel',
'url': 'http://www.linkedin.com/',
'trackingPattern': /www\.linkedin\.com\/emimp\//
}, {
'name': 'MailChimp',
'url': 'http://www.mailchimp.com/',
'trackingPattern': /list\-manage\.com\/track\//
}, {
'name': 'MANDRILL',
'url': 'https://mandrillapp.com/',
'trackingPattern': /mandrillapp\.com\/track\//
}, {
'name': 'NewRelic\'s Tracking Pixel',
'url': 'http://newrelic.com/',
'trackingPattern': /rpm\.newrelic\.com\/tracking\//
}, {
'name': 'Quora\'s Tracking Pixel',
'url': 'https://www.quora.com/',
'trackingPattern': /\.quoramail\.com\/wf\/open/
}, {
'name': 'Sidekick',
'url': 'http://www.getsidekick.com/',
'trackingPattern': /\:\/\/t\.signalequattro\.com\//
}, {
'name': 'Streak',
'url': 'https://www.streak.com/',
'trackingPattern': /mailfoogae\.appspot\.com\//
}, {
'name': 'Trello\'s Tracking Pixel',
'url': 'https://trello.com/',
'trackingPattern': /e\.trello\.com\/track\/open\.php/
}, {
'name': 'Uber\'s Tracking Pixel',
'url': 'https://www.uber.com/',
'trackingPattern': /click\.et\.uber\.com\/open\.aspx/
}, {
'name': 'Yesware',
'url': 'http://www.yesware.com/',
'trackingPattern': /t\.yesware\.com\//
}];
/*
* List of mail service, must have name and proxyPath
* proxyPath will be required by chrome.webRequest.onBeforeRequest
*/
var mails = [{
'name': 'Gmail',
'proxyPath': '*://*.googleusercontent.com/proxy/*'
}];
/*
* Creating a list of all paths to monitor, required by chrome.webRequest.onBeforeRequest
*/
var allProxyPath = mails.map(function(mail) { return mail.proxyPath; });
chrome.webRequest.onBeforeRequest.addListener(function(details){
/*
* Block the request if it is to the tracker
* Send message to content script to display blocking alert
*/
var cancel = trackers.reduce(function(previousValue, currentValue, index, array){
var hasTracker = (currentValue.trackingPattern && details.url && details.url.match(currentValue.trackingPattern))?true:false;
if(hasTracker){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
'event': 'blockTracking',
'name': currentValue.name
});
});
}
return previousValue || hasTracker;
}, false);
return {
cancel: cancel
};
}, {urls: allProxyPath}, ["blocking"]);
}());