|
@@ -1,7 +1,3 @@
|
1
|
|
-// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
2
|
|
-// Use of this source code is governed by a BSD-style license that can be
|
3
|
|
-// found in the LICENSE file.
|
4
|
|
-
|
5
|
1
|
/**
|
6
|
2
|
* Get the current URL.
|
7
|
3
|
*
|
|
@@ -9,48 +5,44 @@
|
9
|
5
|
* is found.
|
10
|
6
|
*/
|
11
|
7
|
function getCurrentTabUrl(callback) {
|
12
|
|
- // Query filter to be passed to chrome.tabs.query - see
|
13
|
|
- // https://developer.chrome.com/extensions/tabs#method-query
|
14
|
8
|
var queryInfo = {
|
15
|
9
|
active: true,
|
16
|
10
|
currentWindow: true
|
17
|
11
|
};
|
18
|
12
|
|
19
|
13
|
chrome.tabs.query(queryInfo, function(tabs) {
|
20
|
|
- // chrome.tabs.query invokes the callback with a list of tabs that match the
|
21
|
|
- // query. When the popup is opened, there is certainly a window and at least
|
22
|
|
- // one tab, so we can safely assume that |tabs| is a non-empty array.
|
23
|
|
- // A window can only have one active tab at a time, so the array consists of
|
24
|
|
- // exactly one tab.
|
25
|
14
|
var tab = tabs[0];
|
26
|
15
|
|
27
|
|
- // A tab is a plain object that provides information about the tab.
|
28
|
|
- // See https://developer.chrome.com/extensions/tabs#type-Tab
|
29
|
16
|
var url = tab.url;
|
30
|
17
|
|
31
|
|
- // tab.url is only available if the "activeTab" permission is declared.
|
32
|
|
- // If you want to see the URL of other tabs (e.g. after removing active:true
|
33
|
|
- // from |queryInfo|), then the "tabs" permission is required to see their
|
34
|
|
- // "url" properties.
|
35
|
18
|
console.assert(typeof url == 'string', 'tab.url should be a string');
|
36
|
19
|
|
37
|
20
|
callback(url);
|
38
|
21
|
});
|
39
|
|
-
|
40
|
|
- // Most methods of the Chrome extension APIs are asynchronous. This means that
|
41
|
|
- // you CANNOT do something like this:
|
42
|
|
- //
|
43
|
|
- // var url;
|
44
|
|
- // chrome.tabs.query(queryInfo, function(tabs) {
|
45
|
|
- // url = tabs[0].url;
|
46
|
|
- // });
|
47
|
|
- // alert(url); // Shows "undefined", because chrome.tabs.query is async.
|
48
|
22
|
}
|
49
|
23
|
|
50
|
|
-function renderStatus(statusText) {
|
51
|
|
- document.getElementById('status').textContent = statusText;
|
|
24
|
+function takeMeTo(url) {
|
|
25
|
+ updateProperties = {
|
|
26
|
+ url: "https://" + url
|
|
27
|
+ }
|
|
28
|
+ chrome.tabs.update(updateProperties=updateProperties)
|
52
|
29
|
}
|
53
|
30
|
|
54
|
31
|
getCurrentTabUrl(function(url) {
|
55
|
|
- renderStatus(url.match(/:\/\/(.+)\//)[1])
|
|
32
|
+ chrome.storage.local.get("sites", function(sites){
|
|
33
|
+ sites = sites.sites
|
|
34
|
+ domain = url.match(/:\/\/(.+)\//)[1]
|
|
35
|
+ if(domain in sites) {
|
|
36
|
+ proxies = sites[url.match(/:\/\/(.+)\//)[1]]
|
|
37
|
+ $("#mirror").css("display", "block")
|
|
38
|
+ $("#nomirror").css("display", "none")
|
|
39
|
+ $("#mirror button").on("click", function() {
|
|
40
|
+ takeMeTo(proxies[Math.floor(Math.random()*proxies.length)])
|
|
41
|
+ })
|
|
42
|
+ }
|
|
43
|
+ else {
|
|
44
|
+ $("#mirror").css("display", "none")
|
|
45
|
+ $("#nomirror").css("display", "block")
|
|
46
|
+ }
|
|
47
|
+ })
|
56
|
48
|
})
|