From 462ca78e5c63682c06f96dade70d193b9e1b68c1 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Fri, 11 Sep 2015 12:08:45 +0000 Subject: Popup ready --- js/popup.js | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'js/popup.js') 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 -- cgit v1.2.3