
chrome.runtime.onMessage.addListener(
    function (request, sender, sendResponse) {
		if (request.cmd == "geturl") {
			$.ajax({
				url: request.data,
				type: "get",
				async: true,
				success: function (rs, textStatus) {
					regx = /URL='([\s\S]+?)'"/i;
					var res=regx.exec(c);
                    sendResponse(res[1]);
                },
				error: function () {}
			})
			
        }
		
		
		
		
		
        if (request.cmd == "state") {
            $.ajax({
				url: 'http://127.0.0.1:35835/state/' + request.params+"/"+request.username,
                type: 'get',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }
        if (request.cmd == "lc") {
            $.ajax({
                url: "http://127.0.0.1:35835/check/" + request.params,
                type: 'get',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }

        if (request.cmd == "rs") {
            $.ajax({
                url: "http://127.0.0.1:35835/result/" + request.params,
                type: 'get',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }
        else if (request.cmd == "read") {
            $.ajax({
                url: "http://127.0.0.1:35836/"+request.params,
                data: request.data,
                type: 'POST',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }
        else if (request.cmd == "writing") {
            $.ajax({
                url: "http://127.0.0.1:35837/collect",
                data: request.data,
                type: 'post',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }
        else if (request.cmd == "rate") {
            $.ajax({
                url: "http://127.0.0.1:35837/rate",
                data: request.data,
                type: 'post',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }
		else if (request.cmd == "etao_resolve_data") {
            $.ajax({
                url: "http://127.0.0.1:35836/etao_resolve_data",
                data: request.data,
                type: 'post',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }
		
		else if (request.cmd == "etao_async") {
            $.ajax({
                url: "http://127.0.0.1:35836/etao_async",
                data: request.data,
                type: 'post',
                contentType: "text",
                async: false,
                success: function (rs, textStatus) {
                    sendResponse(rs)
                }
            });
        }
    }
);