forked from gdg/PixelBlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbg.js
28 lines (24 loc) · 982 Bytes
/
bg.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
chrome.webRequest.onBeforeSendHeaders.addListener(function(req){
var blocking_response = {}, print_mode = false;
// 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 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/') > 0) {
from_gmail = true;
// check if we're in print-mode in gmail
if (headers[i].value.indexOf('view=pt') >= 0) print_mode = true;
break;
}
}
}
// When in print mode allow all images to laod
// TODO: Apply blocking logic to these images
if(req.type == 'image' && !safe && from_gmail && !print_mode){
blocking_response.cancel = true;
}
return blocking_response;
},
{urls: [ "*://*.googleusercontent.com/proxy/*" ]},['requestHeaders','blocking']);