var getConfig = function(url){
	var xhr = new XMLHttpRequest();
	xhr.open("GET", "http://localhost:8999/getAccount?url="+url, false);
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
		  responseText = xhr.responseText;
		  //alert(responseText);
		  //chrome.tabs.executeScript(null, {code:xhr.responseText});
		  config = JSON.parse(responseText);
		}
	}
	xhr.send();
	return config;
}

var injectionCode = function(code){
	var scripts = document.createElement("script");
	scripts.type = "text/javascript";
	scripts.textContent = code;
	document.documentElement.appendChild(scripts);
}

var injectionScriptFile = function(file){
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = file;
	document.documentElement.appendChild(script);
}

var url = window.location.href;
var config = getConfig(url);

//if(url.indexOf('pass/serviceLogin')!=-1){
//	injectionScriptFile('http://www.xiaomi.com/js/libs/jquery18.js');
//}
injectionCode(config.injectionCode);
