diff options
| author | Einar Egilsson <einar@einaregilsson.com> | 2015-09-11 12:08:45 +0000 | 
|---|---|---|
| committer | Einar Egilsson <einar@einaregilsson.com> | 2015-09-11 12:08:45 +0000 | 
| commit | 462ca78e5c63682c06f96dade70d193b9e1b68c1 (patch) | |
| tree | b28a1b279ea523efc021856cd878f41972a0125a | |
| parent | 4c7ba5856ce3bf2976094e2c19d1f99054929360 (diff) | |
Popup ready
| -rw-r--r-- | css/popup.css | 30 | ||||
| -rw-r--r-- | js/background.js | 25 | ||||
| -rw-r--r-- | js/popup.js | 47 | ||||
| -rw-r--r-- | manifest.json | 2 | ||||
| -rw-r--r-- | popup.html | 8 | 
5 files changed, 95 insertions, 17 deletions
diff --git a/css/popup.css b/css/popup.css new file mode 100644 index 0000000..7451ec8 --- /dev/null +++ b/css/popup.css @@ -0,0 +1,30 @@ + +body { +	width:180px; +	text-align: center; +	font-family: Arial, sans-serif; +} + +h1 { +	margin-top:-4px; +	font-size:22px; +	font-weight: bold; +} + +h1 span { +	position: relative; +	top:1px; +	font-size:38px; +} + +button { +	display:block; +	width:90%; +	margin:5px auto !important; +} + +.disabled { +	margin-top:-16px; +	color:red; +	height:13px; +}
\ No newline at end of file diff --git a/js/background.js b/js/background.js index b6260d7..35b1243 100644 --- a/js/background.js +++ b/js/background.js @@ -23,3 +23,28 @@ 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(); +	} +}); +       
\ No newline at end of file diff --git a/js/popup.js b/js/popup.js index fbff178..9aa13cf 100644 --- a/js/popup.js +++ b/js/popup.js @@ -1,13 +1,34 @@ -function hi() { -	chrome.browserAction.setIcon({ -  		path: { -    		19: "images/icon19disabled.png", -    		38: "images/icon38disabled.png" -  		} -  	}); -  	open('redirector.html'); -} - -document.addEventListener('DOMContentLoaded', function() { -	document.getElementsByTagName('button')[0].addEventListener('click', hi); -})
\ No newline at end of file + +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); +			} +		}); +	}; +}]);
\ No newline at end of file diff --git a/manifest.json b/manifest.json index 20d0b2f..75579fa 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@                 "48": "images/icon48active.png",                "128": "images/icon128active.png" }, -  "permissions" : ["webRequest", "webRequestBlocking", "storage", "http://*/*", "https://*/*"], +  "permissions" : ["webRequest", "webRequestBlocking", "storage", "tabs", "http://*/*", "https://*/*"],    "applications": {      "gecko": {        "id": "redirector@einaregilsson.com" @@ -7,8 +7,10 @@  		<script src="js/angular.min.js"></script>  		<script src="js/popup.js"></script>  	</head> -	<body > -		<h1>Redirector</h1> -		<button>Disable</button> +	<body ng-app="popupApp" ng-controller="PopupCtrl"> +		<h1><span>☈</span>edirector</h1> +		<div class="disabled"><span ng-show="disabled">Disabled</span></div> +		<button ng-click="toggleDisabled()">{{disabled ? 'Enable Redirector' : 'Disable Redirector'}}</button> +		<button ng-click="openRedirectorSettings()">Edit Redirects</button>  	</body>  </html>  | 
