aboutsummaryrefslogtreecommitdiff
path: root/js/background.js
blob: 35b124338f31a120b8c64a4ddb98ca5b76398bc9 (plain) (blame)
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
function checkForRedirect(details) {

	//We only allow GET request to be redirected, don't want to accidentally redirect
	//sensitive POST parameters
	if (details.method != 'GET') {
		return null;
	}

  	if (details.url.match(/mbl\.is/)) {
  		console.log('Redirecting ' + details.url);
  		return  {redirectUrl: 'http://foo.is'}; //this doesn't work
  	}
  	return  null; //{redirectUrl: 'http://foo.is'}; //this doesn't work
}


var filter = {urls:["http://*/*", "https://*/*"]};

//TODO: Better browser detection...
var isFirefox = !!navigator.userAgent.match(/Firefox\//);

var ev = isFirefox ? chrome.webRequest.onBeforeSendHeaders : chrome.webRequest.onBeforeRequest;
ev.addListener(checkForRedirect, filter, ["blocking"]);

var storage = chrome.storage.local; //TODO: Change to sync when Firefox supports it...


//Icon updating code below

function updateIcon() {
	storage.get({disabled:false}, function(obj) {
		chrome.browserAction.setIcon({
	  		path: {
	    		19: obj.disabled ? "images/icon19disabled.png" : "images/icon19active.png",
	    		38: obj.disabled ? "images/icon38disabled.png" : "images/icon38active.png"  
	  		}
	  	});
	});	
}

updateIcon();

chrome.storage.onChanged.addListener(function(changes, namespace) {
	if (changes.disabled) {
		updateIcon();
	}
});