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 /js | |
parent | 4c7ba5856ce3bf2976094e2c19d1f99054929360 (diff) |
Popup ready
Diffstat (limited to 'js')
-rw-r--r-- | js/background.js | 25 | ||||
-rw-r--r-- | js/popup.js | 47 |
2 files changed, 59 insertions, 13 deletions
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 |