Firefox的searchbar默认内置了Google,Bing,Ask,eBay等搜索引擎,但其实除了Google外,别的都不怎么常用。我常用的一个搜索引擎是百Google度,它能同时显示Google和百度的搜索结果。但是,firefox自然没有内置这样一款搜索引擎,而且firefox也没有提供添加搜索引擎的便利方法,于是,得自己动手了。
(在做这项工作的时候,我是在Ubuntu 11.10的环境下,firefox也是最新的9.0,所以下文以此为准,当然Windows环境下应该大同小异。)
firefox装在目录/etc/lib下,到该目录执行ls,找到目录firefox-addons,于是一路的ls,cd下去,最终进入目录/usr/lib/firefox-addons/searchplugins/en-US(刚找了一下,windows下firefox的搜索引擎定义文件存放目录为:%FIREFOX%\searchplugins,其中%FIREFOX%代表firefox安装目录),可以看到该目录下有一大堆关于搜索引擎定义的xml文件,运行vi google.xml,其内容如下:
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Google</ShortName>
<Description>Google Search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/png;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADs9Pt8xetPtu9FsfFNtu%2BTzvb2%2B%2Fne4dFJeBw0egA%2FfAJAfAA8ewBBegAAAAD%2B%2FPtft98Mp%2BwWsfAVsvEbs%2FQeqvF8xO7%2F%2F%2F63yqkxdgM7gwE%2FggM%2BfQA%2BegBDeQDe7PIbotgQufcMufEPtfIPsvAbs%2FQvq%2Bfz%2Bf%2F%2B%2B%2FZKhR05hgBBhQI8hgBAgAI9ewD0%2B%2Fg3pswAtO8Cxf4Kw%2FsJvvYAqupKsNv%2B%2Fv7%2F%2FP5VkSU0iQA7jQA9hgBDgQU%2BfQH%2F%2Ff%2FQ6fM4sM4KsN8AteMCruIqqdbZ7PH8%2Fv%2Fg6Nc%2Fhg05kAA8jAM9iQI%2BhQA%2BgQDQu6b97uv%2F%2F%2F7V8Pqw3eiWz97q8%2Ff%2F%2F%2F%2F7%2FPptpkkqjQE4kwA7kAA5iwI8iAA8hQCOSSKdXjiyflbAkG7u2s%2F%2B%2F%2F39%2F%2F7r8utrqEYtjQE8lgA7kwA7kwA9jwA9igA9hACiWSekVRyeSgiYSBHx6N%2F%2B%2Fv7k7OFRmiYtlAA5lwI7lwI4lAA7kgI9jwE9iwI4iQCoVhWcTxCmb0K%2BooT8%2Fv%2F7%2F%2F%2FJ2r8fdwI1mwA3mQA3mgA8lAE8lAE4jwA9iwE%2BhwGfXifWvqz%2B%2Ff%2F58u%2Fev6Dt4tr%2B%2F%2F2ZuIUsggA7mgM6mAM3lgA5lgA6kQE%2FkwBChwHt4dv%2F%2F%2F728ei1bCi7VAC5XQ7kz7n%2F%2F%2F6bsZkgcB03lQA9lgM7kwA2iQktZToPK4r9%2F%2F%2F9%2F%2F%2FSqYK5UwDKZAS9WALIkFn%2B%2F%2F3%2F%2BP8oKccGGcIRJrERILYFEMwAAuEAAdX%2F%2Ff7%2F%2FP%2B%2BfDvGXQLIZgLEWgLOjlf7%2F%2F%2F%2F%2F%2F9QU90EAPQAAf8DAP0AAfMAAOUDAtr%2F%2F%2F%2F7%2B%2Fu2bCTIYwDPZgDBWQDSr4P%2F%2Fv%2F%2F%2FP5GRuABAPkAA%2FwBAfkDAPAAAesAAN%2F%2F%2B%2Fz%2F%2F%2F64g1C5VwDMYwK8Yg7y5tz8%2Fv%2FV1PYKDOcAAP0DAf4AAf0AAfYEAOwAAuAAAAD%2F%2FPvi28ymXyChTATRrIb8%2F%2F3v8fk6P8MAAdUCAvoAAP0CAP0AAfYAAO4AAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAA</Image>
<Url type="application/x-suggestions+json" method="GET" template="http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl={moz:locale}&q={searchTerms}"/>
<Url type="text/html" method="GET" template="http://www.google.com/search">
<Param name="client" value="ubuntu"/>
<Param name="channel" value="fs"/>
<Param name="q" value="{searchTerms}"/>
<Param name="ie" value="utf-8"/>
<Param name="oe" value="utf-8"/>
</Url>
<SearchForm>http://www.google.com/</SearchForm>
</SearchPlugin>
可以看到是关于Google搜索的一些定义,于是我们照葫芦画瓢,新建一个baigoogledu.xml文件,内容如下:
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>BG</ShortName>
<Description>self defined search engine</Description>
<InputEncoding>GB2312</InputEncoding> <!-- 注意,这里只能是GB2312,不能是UTF-8 -->
<Image width="16" height="16" type="image/x-icon"></Image> <!-- 这里应该是logo的base64编码字符串,暂时没有找到比较简单的方法来获取,就先置空好了 -->
<Url type="text/html" method="GET" template="http://www.baigoogledu.com/s.php">
<Param name="hl" value="zh-CN"/>
<Param name="q" value="{searchTerms}"/>
</Url>
<SearchForm>http://www.baigoogledu.com/s.php</SearchForm>
</SearchPlugin>
上面xml定义中,InputEncoding只能是GB2312,不能是UTF-8,因为baigoogledu页面指定的encoding是gb2312,所以如果用UTF-8的话,搜索中文会出现乱码。
好了,重启firefox,searchbar里面就会出现我们刚定义的baigoogledu搜索引擎了(当然,它其实不算是一个搜索引擎)。另外,如果哪位有比较好的获得网站logo的base64编码的方法的话,还望不吝赐教。