Procházet zdrojové kódy

Adapted code to JSON change

Brendan Abolivier před 8 roky
rodič
revize
0e42c71b59
2 změnil soubory, kde provedl 3 přidání a 24 odebrání
  1. 2
    23
      eventPage.js
  2. 1
    1
      popup.js

+ 2
- 23
eventPage.js Zobrazit soubor

@@ -6,49 +6,28 @@ function getSitesAndMirrors() {
6 6
 }
7 7
 
8 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 9
   var queryInfo = {
12 10
     active: true,
13 11
     currentWindow: true
14 12
   };
15 13
 
16 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 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 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 19
     console.assert(typeof url == 'string', 'tab.url should be a string');
33 20
 
34 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 25
 function updateTab() {
48 26
     getCurrentTabUrl(function(url) {
49 27
         chrome.storage.local.get("sites", function(sites){
50 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 31
                 chrome.browserAction.setIcon({path: 'icon-red.png'})
53 32
             }
54 33
             else {

+ 1
- 1
popup.js Zobrazit soubor

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