Browse Source

Adapted code to JSON change

Brendan Abolivier 8 years ago
parent
commit
0e42c71b59
2 changed files with 3 additions and 24 deletions
  1. 2
    23
      eventPage.js
  2. 1
    1
      popup.js

+ 2
- 23
eventPage.js View File

6
 }
6
 }
7
 
7
 
8
 function getCurrentTabUrl(callback) {
8
 function getCurrentTabUrl(callback) {
9
-  // Query filter to be passed to chrome.tabs.query - see
10
-  // https://developer.chrome.com/extensions/tabs#method-query
11
   var queryInfo = {
9
   var queryInfo = {
12
     active: true,
10
     active: true,
13
     currentWindow: true
11
     currentWindow: true
14
   };
12
   };
15
 
13
 
16
   chrome.tabs.query(queryInfo, function(tabs) {
14
   chrome.tabs.query(queryInfo, function(tabs) {
17
-    // chrome.tabs.query invokes the callback with a list of tabs that match the
18
-    // query. When the popup is opened, there is certainly a window and at least
19
-    // one tab, so we can safely assume that |tabs| is a non-empty array.
20
-    // A window can only have one active tab at a time, so the array consists of
21
-    // exactly one tab.
22
     var tab = tabs[0];
15
     var tab = tabs[0];
23
 
16
 
24
-    // A tab is a plain object that provides information about the tab.
25
-    // See https://developer.chrome.com/extensions/tabs#type-Tab
26
     var url = tab.url;
17
     var url = tab.url;
27
 
18
 
28
-    // tab.url is only available if the "activeTab" permission is declared.
29
-    // If you want to see the URL of other tabs (e.g. after removing active:true
30
-    // from |queryInfo|), then the "tabs" permission is required to see their
31
-    // "url" properties.
32
     console.assert(typeof url == 'string', 'tab.url should be a string');
19
     console.assert(typeof url == 'string', 'tab.url should be a string');
33
 
20
 
34
     callback(url);
21
     callback(url);
35
   });
22
   });
36
-
37
-  // Most methods of the Chrome extension APIs are asynchronous. This means that
38
-  // you CANNOT do something like this:
39
-  //
40
-  // var url;
41
-  // chrome.tabs.query(queryInfo, function(tabs) {
42
-  //   url = tabs[0].url;
43
-  // });
44
-  // alert(url); // Shows "undefined", because chrome.tabs.query is async.
45
 }
23
 }
46
 
24
 
47
 function updateTab() {
25
 function updateTab() {
48
     getCurrentTabUrl(function(url) {
26
     getCurrentTabUrl(function(url) {
49
         chrome.storage.local.get("sites", function(sites){
27
         chrome.storage.local.get("sites", function(sites){
50
             sites = sites.sites
28
             sites = sites.sites
51
-            if(url.match(/:\/\/([^\/]+)\//)[1] in sites) {
29
+            domain = url.match(/:\/\/(www\.)?([^\/]+)\//).slice(-1)[0]
30
+            if(domain in sites) {
52
                 chrome.browserAction.setIcon({path: 'icon-red.png'})
31
                 chrome.browserAction.setIcon({path: 'icon-red.png'})
53
             }
32
             }
54
             else {
33
             else {

+ 1
- 1
popup.js View File

31
 getCurrentTabUrl(function(url) {
31
 getCurrentTabUrl(function(url) {
32
     chrome.storage.local.get("sites", function(sites){
32
     chrome.storage.local.get("sites", function(sites){
33
         sites = sites.sites
33
         sites = sites.sites
34
-        domain = url.match(/:\/\/([^\/]+)\//)[1]
34
+        domain = url.match(/:\/\/(www\.)?([^\/]+)\//).slice(-1)[0]
35
         if(domain in sites) {
35
         if(domain in sites) {
36
             proxies = sites[domain]
36
             proxies = sites[domain]
37
             $("#mirror").css("display", "block")
37
             $("#mirror").css("display", "block")