From 462ca78e5c63682c06f96dade70d193b9e1b68c1 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Fri, 11 Sep 2015 12:08:45 +0000 Subject: Popup ready --- css/popup.css | 30 ++++++++++++++++++++++++++++++ js/background.js | 25 +++++++++++++++++++++++++ js/popup.js | 47 ++++++++++++++++++++++++++++++++++------------- manifest.json | 2 +- popup.html | 8 +++++--- 5 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 css/popup.css 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" diff --git a/popup.html b/popup.html index 5e7e81f..f651ab0 100644 --- a/popup.html +++ b/popup.html @@ -7,8 +7,10 @@ - -

Redirector

- + +

edirector

+
Disabled
+ + -- cgit v1.2.3