|
@@ -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 {
|