我目前正在玩Chrome扩展程序。我想抓住谷歌搜索参数(即关键字查询)并使用它们来显示evernote extension所做的其他内容。
有人知道他们是如何实施的吗?
现在已经看了很长一段时间的源代码,但找不到任何东西。
答案 0 :(得分:3)
搜索词是搜索网址的q参数,所以在后台页面中你可以监视标签,然后使用parseUri(http://blog.stevenlevithan.com/archives/parseuri)来解析网址并获取q值。
这样的事情......
background.js
// make sure you include the parseUri listed above
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
{
uri = parseUri(tab.url);
if ((uri.host.indexOf('google')!=-1)&&(uri.path=='/search')){
// do something with the search term
console.debug('Search term was : ' + unescape(uri.queryKey.q));
}
});