aboutsummaryrefslogtreecommitdiff
path: root/js/popup.js
blob: 1e9d35399e488bc1f7a5f56f233c5660d98dd554 (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
angular.module('popupApp', []).controller('PopupCtrl', ['$scope', function($s) {

	var storage = chrome.storage.local; //TODO: Change to sync when Firefox supports it...
	
	storage.get({disabled:false}, function(obj) {
		$s.disabled = obj.disabled;
		$s.$apply();
	});

	$s.toggleDisabled = function() {
		storage.get({disabled:false}, function(obj) {
			storage.set({disabled:!obj.disabled});
		  	$s.disabled = !obj.disabled;
		  	$s.$apply();
		});
	};

	$s.openRedirectorSettings = function() {

		//switch to open one if we have it to minimize conflicts
		var url = chrome.extension.getURL('redirector.html');

		chrome.tabs.query({currentWindow:true, url:url}, function(tabs) {
			if (tabs.length > 0) {
				chrome.tabs.update(tabs[0].id, {active:true}, function(tab) {
					close();
				});
			} else {
				open(url);
			}
		});
	};
}]);