var win = chrome.extension.getBackgroundPage();
var proxy = win.proxy;
var activeName = localStorage.activeProxyName || 'whistle';

var proxyList = $('#proxyList').on('click', 'a', function(e) {
	var self = $(this);
	if (!self.hasClass('selected')) {
		proxyList.find('a').removeClass('selected');
		localStorage.activeProxyName = self.attr('data-name');
		self.addClass('selected');
		$('#proxyName').select().focus();
	}
	
	return false;
}).on('mousedown', 'a', function() {
	var self = $(this);
	if (self.hasClass('selected')) {
		return false;
	}
});

$('#createProxy').click(function() {
	var name = $.trim(prompt('请输入不超过36个字符的代理名称：'));
	if (!name || !(name = name.trim())) {
		return false;
	}
	name = name.substring(0, 36);
	if (proxy.getProxy(name)) {
		alert('`' + name + '`已经存在，请重新创建');
		return false;
	}
	createProxyElem(name).appendTo('#proxyList').trigger('click');
	return false;
});

function createProxyElem(name) {
	var item = $('<a href="javascript:;">whistle</a>');
	item.attr('data-name', name);
	item.text(name);
	return item;
}

proxyList.find('a[data-name="' + activeName.replace(/(["\\])/g, '\\$1') +'"]').trigger('click');
@@ -67,68 +67,8 @@
 oxy;
-%0Avar activeName = localStorage.activeProxyName %7C%7C 'whistle';
 %0A%0Ava
@@ -237,59 +237,215 @@
 ;%0A%09%09
-localStorage.activeProxyName = self.attr('data-name
+var name = self.attr('data-name');%0A%09%09localStorage.activeProxyName = name;%0A%09%09$('#proxyName').val(name %7C%7C '');%0A%09%09$('#proxyIP').val(self.attr('data-ip') %7C%7C '');%0A%09%09$('#proxyPort').val(self.attr('data-port') %7C%7C '
 ');%0A
@@ -645,16 +645,49 @@
 %09%7D%0A%7D);%0A%0A
+var proxyList = $('#proxyList');%0A
 $('#crea
@@ -938,16 +938,39 @@
 lse;%0A%09%7D%0A
+%09proxy.setProxy(name);%0A
 %09createP
@@ -993,18 +993,16 @@
 ppendTo(
-'#
 proxyLis
@@ -1002,17 +1002,16 @@
 roxyList
-'
 ).trigge
@@ -1071,16 +1071,28 @@
 lem(name
+, host, port
 ) %7B%0A%09var
@@ -1147,24 +1147,28 @@
 %0A%09item.attr(
+%7B%0A%09%09
 'data-name',
@@ -1170,52 +1170,311 @@
 ame'
-,
+:
  name
-);%0A%09item.text(name);%0A%09return item;%0A%7D%0A%0A
+,%0A%09%09'data-host': host,%0A%09%09'data-port': port%0A%09%7D);%0A%09%0A%09item.text(name);%0A%09return item;%0A%7D%0A%0Afunction init() %7B%0A%09proxy.getProxyConfig.list.forEach(function(item) %7B%0A%09%09createProxyElem(item.name, item.host, item, port).appendTo(proxyList);%0A%09%7D);%0A%09%0A%09var activeName = localStorage.activeProxyName %7C%7C 'whistle';%0A%09
 prox
@@ -1549,24 +1549,27 @@
 +'%22%5D').trigger('click');
+%0A%7D%0A

handle edit proxy