2

我的问题是关于多功能框。Chrome API 提供的想法,我想知道清单上是否有可能有多个关键字。

我正在考虑一个正则表达式或类似的东西,但我真的不知道该怎么做......

4

2 回答 2

0

对不起,不可能。

我看到您仍在尝试制作自定义搜索提供程序。我想告诉你我在类似的扩展中做了什么,例如,如果你用大写字母键入关键字,它会触发谷歌幸运搜索而不是常规搜索。它有一些陷阱和限制(最大的一个是默认搜索提供者必须是 google,它仍然会简要显示 google 搜索结果),但至少有一些:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
      if(changeInfo.status == "loading") {
              var url = $.url.setUrl(tab.url);
               if((url.attr("protocol") == "https" && url.attr("host").indexOf("encrypted.google.") == 0
                                      || url.attr("protocol") == "http" && url.attr("host").indexOf("www.google.") == 0)
                              && url.attr("path") == "/search" && url.param("q") && isAllCapital(url.param("q"))) {

                      //do something with search term inside url.param("q")
              }
      }
});

(我正在使用URL Parser插件)。

于 2011-03-18T16:26:25.917 回答
0

我想我刚刚找到了解决方案。

我发现当您使用 google 搜索“TRY”时,网址是:

http://www.google.com/#sclient=psy&hl=fr&site=&source=hp&q=TRY&aq=f&aqi=&aql=&oq=&pbx=1&fp=ec3d6f66084ab746

当它来自 Chrome URL 时,它是:

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=TRY

所以基本上,如果我检查 url 上是否有 sourceid=Chrome,我可以像这样重定向。你怎么看 ?

// If Google Search from the URL (sourceid)
if(URL.match('google') && parseUri(URL).queryKey['sourceid'] == 'chrome')
{
    chrome.tabs.update(tabId, { url: 'http://search.yahoo.com/search?p=' + parseUri(URL).queryKey['q'] });
    return;
} // If Bing Search from the URL (setmkt)
else if(URL.match('bing') && parseUri(URL).queryKey['setmkt'])
{
    chrome.tabs.update(tabId, { url: 'http://search.yahoo.com/search?p=' + parseUri(URL).queryKey['p'] });
    return;
}
于 2011-03-18T16:40:26.927 回答