记录一下Chrome 插件开发的一些小Tips。
代码如下:
chrome.browserAction.setBadgeBackgroundColor({color: '#c8112f'});
chrome.browserAction.setBadgeText({text: number, tabId: tabID });
后台代码
chrome.runtime.onConnect.addListener(function (port) {
port.postMessage({
type:"info",
totalResultsCount: count,
where: where
});
});
消息的内容是
{type:"info", totalResultsCount: count, where: where }
于是在前台我们可以这么写。
当消息的类型是info
时,我们就从消息中读取相应的内容。
port.onMessage.addListener(function(message, sender){
if(message.type === "info"){
if($('#header').length === 0){
$("html").append("<div id='header'>" +
" <div class='header'>We found " + message.totalResultsCount + " results in " + message.where + "</div></div>");
}
}
});
围观我的Github Idea墙, 也许,你会遇到心仪的项目