//发送消息到contentscript
function sendMessageToContentScript(message, tab, callback) {
	chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
		chrome.tabs.sendMessage(tab.id, message, function (response) {
			if (callback) callback(response);
		});
	});
}

//发送消息到backgroundscript
function sendMessageToBackgroudScript(type, params, callback) {
	// 处理3个参数的情况：type, params, callback
	if (arguments.length === 3) {
		chrome.runtime.sendMessage({ type, params }, function (response) {
			if (callback) callback(response);
		});
	} 
	// 处理2个参数的情况：message, callback
	else {
		chrome.runtime.sendMessage(type, function (response) {
			if (params) params(response);
		});
	}
}