| 
				
			 | 
			
			
				@@ -2,47 +2,52 @@ 
			 | 
		
	
		
			
			| 
				2
			 | 
			
				2
			 | 
			
			
				  * Get the current URL. 
			 | 
		
	
		
			
			| 
				3
			 | 
			
				3
			 | 
			
			
				  * 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				4
			 | 
			
			
				  * @param {function(string)} callback - called when the URL of the current tab 
			 | 
		
	
		
			
			| 
				5
			 | 
			
				
			 | 
			
			
				- *   is found. 
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+ * is found. 
			 | 
		
	
		
			
			| 
				6
			 | 
			
				6
			 | 
			
			
				  */ 
			 | 
		
	
		
			
			| 
				7
			 | 
			
				7
			 | 
			
			
				 function getCurrentTabUrl(callback) { 
			 | 
		
	
		
			
			| 
				8
			 | 
			
				
			 | 
			
			
				-  var queryInfo = { 
			 | 
		
	
		
			
			| 
				9
			 | 
			
				
			 | 
			
			
				-    active: true, 
			 | 
		
	
		
			
			| 
				10
			 | 
			
				
			 | 
			
			
				-    currentWindow: true 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				
			 | 
			
			
				-  }; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				8
			 | 
			
			
				+	var queryInfo = { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				+		active: true, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				10
			 | 
			
			
				+		currentWindow: true 
			 | 
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				+	}; 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				12
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				13
			 | 
			
				
			 | 
			
			
				-  chrome.tabs.query(queryInfo, function(tabs) { 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				
			 | 
			
			
				-    var tab = tabs[0]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+	chrome.tabs.query(queryInfo, function(tabs) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+		var tab = tabs[0]; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				+		var url = tab.url; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+		console.assert(typeof url == 'string', 'tab.url should be a string'); 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				17
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				16
			 | 
			
				
			 | 
			
			
				-    var url = tab.url; 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				
			 | 
			
			
				-    console.assert(typeof url == 'string', 'tab.url should be a string'); 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				
			 | 
			
			
				-    callback(url); 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				
			 | 
			
			
				-  }); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+		callback(url); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+	}); 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				20
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				23
			 | 
			
				21
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+// Redirect to mirror url 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				23
			 | 
			
			
				 function takeMeTo(url) { 
			 | 
		
	
		
			
			| 
				25
			 | 
			
				
			 | 
			
			
				-    updateProperties = { 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				
			 | 
			
			
				-        url: "https://" + url 
			 | 
		
	
		
			
			| 
				27
			 | 
			
				
			 | 
			
			
				-    } 
			 | 
		
	
		
			
			| 
				28
			 | 
			
				
			 | 
			
			
				-    chrome.tabs.update(updateProperties=updateProperties) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+	updateProperties = { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+			url: "https://" + url 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+	chrome.tabs.update(updateProperties=updateProperties) 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				28
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				30
			 | 
			
				29
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+// Check if there's a mirror for the current URL. If so, display the message 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+// about it and the button to redirect to a random mirror (if there's more than 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+// one). 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				33
			 | 
			
			
				 getCurrentTabUrl(function(url) { 
			 | 
		
	
		
			
			| 
				32
			 | 
			
				
			 | 
			
			
				-    chrome.storage.local.get("sites", function(sites){ 
			 | 
		
	
		
			
			| 
				33
			 | 
			
				
			 | 
			
			
				-        sites = sites.sites 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				
			 | 
			
			
				-        domain = url.match(/:\/\/(www\.)?([^\/]+)\//).slice(-1)[0] 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				
			 | 
			
			
				-        if(domain in sites) { 
			 | 
		
	
		
			
			| 
				36
			 | 
			
				
			 | 
			
			
				-            proxies = sites[domain] 
			 | 
		
	
		
			
			| 
				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
			 | 
			
				
			 | 
			
			
				-    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+	chrome.storage.local.get("sites", function(sites){ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+			sites = sites.sites 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+			// Grab the domain part of the URL 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+			domain = url.match(/:\/\/(www\.)?([^\/]+)\//).slice(-1)[0] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+			if(domain in sites) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+					proxies = sites[domain] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+					// Offer the user to redirect them to a mirror 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+					$("#mirror").css("display", "block") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+					$("#nomirror").css("display", "none") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+					$("#mirror button").on("click", function() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+							takeMeTo(proxies[Math.floor(Math.random()*proxies.length)]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+					}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+			} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+			else { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+					// Tell the user there's no mirror available 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+					$("#mirror").css("display", "none") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+					$("#nomirror").css("display", "block") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+			} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+	}) 
			 | 
		
	
		
			
			| 
				48
			 | 
			
				53
			 | 
			
			
				 }) 
			 |