var getConfig = function(){
	var xhr = new XMLHttpRequest();
	xhr.open("GET", "http://localhost:8999/getAccount", 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;
}

//get config infomation
var config = getConfig();
chrome.webNavigation.onCompleted.addListener(function(e) {
	//if the navigation happens in the tab content window
	if(e.frameId == 0){
		var code = config.injectionCode;
		//set user and pass
		if(code.indexOf('{user}')!=-1){
			code = code.replace("{user}", config.user);
		}
		if(code.indexOf('{pass}')!=-1){
			code = code.replace("{pass}", config.pass);
		}
		if(code.indexOf('{action}')!=-1){
			code = code.replace("{action}", config.action);
		}
		//chrome.tabs.executeScript(null, {file: "jquery-1.8.0.min.js"});
		chrome.tabs.executeScript(null, {code: code});
	}
});

chrome.tabs.executeScript(null, {code: config.initLocation});

//$('#su').val('hi baidu');





