论坛's Archiver

wolfg 发表于 2006-2-19 15:39

Mozilla搜索插件在Mozilla和Mozilla Firefox里的表现形式不太一样,但Firefox也可以安装<a href="http://searchsidebar.mozdev.org/" target="_blank">SearchSideBar</a>这个扩展来实现同样的sidebar。<br /><br />为Mozilla添加新的搜索插件很简单,如<a href="http://mycroft.mozdev.org/" target="_blank">Mycroft</a>上所说,只要你懂一点html的知识。Mycroft是搜索插件的“集散地”,你在Firefox的搜索工具栏的下拉菜单里选“添加引擎”就会带你去这里,找到你想用的插件,点击链接安装它们。<br /><br />Mycroft有很详细的<a href="http://mycroft.mozdev.org/deepdocs/deepdocs.html" target="_blank">制作教程</a>,甚至还有一个<a href="http://mycroft.mozdev.org/generator/" target="_blank">plugin生成页面</a>帮你,不过我没试过。<br /><br />下面我结合我为CU精华贴搜索制作的搜索插件来介绍如何制作一个搜索插件。<br /><br />首先,用你最喜欢的文本编辑器新建一个文件。我在Windows下用的是PSPad,你可能喜欢别的,当然用记事本也可以。Unix下就不用多说了,vi、emacs、nano随便你。(真罗嗦啊)<br /><br />先写一些注释信息,以#开头,可以描述一下这个插件是为哪个搜索引擎创建的、作者是谁、最后更新时间等等。这些虽然是可写可不写的,但是强烈建议你加上,至少可以显得我们很专业。像我,就写这么一行:<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b># Mozilla plug-in file for ChinaUnix.net by wolfg &lt;wolfg@mail.com&gt;</b><!--colorc--></span><!--/colorc--><br />关于这些header信息如何写,可以参考<a href="http://mycroft.mozdev.org/deepdocs/headerinfo.html" target="_blank">http://mycroft.mozdev.org/deepdocs/headerinfo.html</a>。<br /><br />下面开始真正的plugin代码。插件代码要求必须以SEARCH标签开始,<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>&lt;search</b><!--colorc--></span><!--/colorc--><br /><br />接下来必须是version这个属性<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>version=&quot;7.1&quot;</b><!--colorc--></span><!--/colorc--><br />注意,这个version并不是指plugin自己的版本。至于7.1这个值是怎么来的,请详细阅读<a href="http://mycroft.mozdev.org/deepdocs/searchtag.html" target="_blank">SEARCH标签的文档</a>。<br /><br />属性name和description都是必须的,name用来显示在选择搜索引擎的下拉菜单里。这里我写的是:<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>name=&quot;ChinaUnix.net&quot;<br />description=&quot;ChinaUnix.net&quot;</b><!--colorc--></span><!--/colorc--><br /><br />属性action、searchForm和method比较重要了,是plugin能否工作正常的条件之一。searchForm要指定包含输入搜索条件表单(Form)的那个页面的url,比如CU的搜索就是http://search.chinaunix.net/cgi-bin/search; action则和搜索表单里的action一样,查看包含表单的那个页面的源代码就知道了;method呢,显然应该跟表单的method属性一样,但是现在只能用GET。<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>method=&quot;GET&quot;<br />action=&quot;http://search.chinaunix.net/cgi-bin/search&quot;<br />searchForm=&quot;http://search.chinaunix.net/cgi-bin/search&quot;</b><!--colorc--></span><!--/colorc--><br /><br />因为CU的搜索是简体中文页面,所以queryEncoding和queryCharset这两个属性也要加上。<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>queryEncoding=&quot;gb2312&quot;<br />queryCharset=&quot;gb2312&quot;</b><!--colorc--></span><!--/colorc--><br /><br />然后呢,用&gt;关闭SEARCH标签的开始部分,跟写html标签一样。<br /><br />在用&lt;/search&gt;来结束SEARCH标签之前,还需要包含INPUT标签和INTERPRET标签。<br /><br />INPUT标签是用来告诉Mozilla把什么信息提交给搜索页面的。<br /><br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>&lt;input name=&quot;sourceid&quot; value=&quot;Mozilla-search&quot;&gt;</b><!--colorc--></span><!--/colorc--><br />这个名为sourceid的INPUT是用来告诉搜索页面是Mozilla-search提交查询请求的,满足网站统计的需要。<br /><br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>&lt;input name=&quot;key&quot; user&gt;</b><!--colorc--></span><!--/colorc--><br />这个也是重要的地方,user表示这个是需要用户在搜索工具栏里输入的查询信息。这种需要用户输入的INPUT标签只能有一个。name的值要看搜索页面的源代码来确定。CU搜索页面的那个input的name是key,所以这里的name也是key。<br /><br />CU的搜索还需要两个信息,forum_num和mode,这些就不能要求用户输入了,所以直接用value来指定固定的值。当然,这些也是通过查看搜索页面的源代码得知的。<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>&lt;input name=&quot;forum_num&quot; value=&quot;-1&quot;&gt;<br />&lt;input name=&quot;mode&quot; value=&quot;title&quot;&gt;</b><!--colorc--></span><!--/colorc--><br /><br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>&lt;inputnext name=&quot;begin&quot; factor=&quot;50&quot;&gt;<br />&lt;inputprev&gt;<br />&lt;inputnext name=&quot;page_n&quot; factor=&quot;1&quot;&gt;<br />&lt;inputprev&gt;</b><!--colorc--></span><!--/colorc--><br />inputnext和inputprev标签比较特殊,用来实现在Mozilla的侧栏(sidebar)里将查询结果分页。factor表示下一 页时属性的增长值。上面的代码表示每次按下“下一页”,begin会增加50,按下“前一页”则减少50。(注:factor是从0开始计算的。而CU的 搜索中page_n这个参数是从1开始的,所以在sidebar里的分页工作得不正常。已经有人提出了<a href="http://cn.iblog.com/http:%20//mycroft.mozdev.org/deepdocs/inputtags.html#c5" target="_blank">这个问题</a>,是个<a href="http://cn.iblog.com/http:%20//mycroft.mozdev.org/deepdocs/inputtags.html#c6" target="_blank">bug</a>吗?)<br /><br />INPUT标签的文档在<a href="http://mycroft.mozdev.org/deepdocs/inputtags.html" target="_blank">这里</a>。<br /> <br /><a href="http://mycroft.mozdev.org/deepdocs/interprettag.html" target="_blank">INTERPRET标签</a>则是用来告诉Mozilla如何解释查询返回的结果的。至少要包括resultListStart、resultListEnd、 resultItemStart和resultItemEnd这四个属性。<br /><br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>&lt;interpret<br />    browserResultType=&quot;result&quot;<br />    charset = &quot;gb2312&quot;<br />    resultListStart   = &#39;&lt;table width=100% border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;0&quot; align=&quot;center&quot;&gt;&#39;<br />    resultListEnd     = &quot;&lt;/table&gt;&quot;<br />    resultItemStart=&quot;&lt;td  &gt;&quot;<br />    resultItemEnd=&quot;&lt;/td&gt;&quot;<br />  &gt;<br /></b><!--colorc--></span><!--/colorc--><br />这里,resultListStart和resultListEnd是告诉Mozilla从什么地方开始查找查询结果,直到遇见什么为止。 resultItemStart和resultItemEnd告诉Mozilla在它们指定的范围内找&lt;a xhref=&quot;&quot;&gt;标签以便生成sidebar里的查询结果列表。<br /><br />现在该用&lt;/search&gt;来结束SEARCH标签了。<br /><br />最后,还需要<a href="http://mycroft.mozdev.org/deepdocs/browsertag.html" target="_blank">BROWSER标签</a>来指定与插件更新相关的一些信息,如更新的url和检查周期。<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><b>&lt;browser<br />  update=&quot;http://mycroft.mozdev.org/update.php/id0/chinaunix.src&quot;<br />  updateIcon=&quot;http://mycroft.mozdev.org/update.php/id0/chinaunix.gif&quot;<br />  updateCheckDays=&quot;7&quot;<br />&gt;</b><!--colorc--></span><!--/colorc--><br /><br /><br />完整的代码如下:<br /><!--coloro:#006600--><span style="color:#006600"><!--/coloro--><br />    <b># Mozilla plug-in file for ChinaUnix.net by wolfg &lt;wolfg@mail.com&gt;<br /><br />    &lt;search<br />      version=&quot;7.1&quot;<br />      name=&quot;ChinaUnix.net&quot;<br />      description=&quot;ChinaUnix.net&quot;<br />      method=&quot;GET&quot;<br />      action=&quot;http://search.chinaunix.net/cgi-bin/search&quot;<br />      searchForm=&quot;http://search.chinaunix.net/cgi-bin/search&quot;<br />      queryEncoding=&quot;gb2312&quot;<br />      queryCharset=&quot;gb2312&quot;<br />    &gt;<br /><br />      &lt;input name=&quot;sourceid&quot; value=&quot;Mozilla-search&quot;&gt;<br />      &lt;input name=&quot;key&quot; user&gt;<br />      &lt;input name=&quot;forum_num&quot; value=&quot;-1&quot;&gt;<br />      &lt;input name=&quot;mode&quot; value=&quot;title&quot;&gt;<br />      &lt;inputnext name=&quot;begin&quot; factor=&quot;50&quot;&gt;<br />      &lt;inputprev&gt;<br />      &lt;inputnext name=&quot;page_n&quot; factor=&quot;1&quot;&gt;<br />      &lt;inputprev&gt;<br />     <br />      &lt;interpret<br />        browserResultType=&quot;result&quot;<br />        charset = &quot;gb2312&quot;<br />        resultListStart   = &#39;&lt;table width=100% border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;0&quot; align=&quot;center&quot;&gt;&#39;<br />        resultListEnd     = &quot;&lt;/table&gt;&quot;<br />        resultItemStart=&quot;&lt;td  &gt;&quot;<br />        resultItemEnd=&quot;&lt;/td&gt;&quot;<br />      &gt;<br />     <br />    &lt;/search&gt;<br /><br />    &lt;browser<br />      update=&quot;http://mycroft.mozdev.org/update.php/id0/chinaunix.src&quot;<br />      updateIcon=&quot;http://mycroft.mozdev.org/update.php/id0/chinaunix.gif&quot;<br />      updateCheckDays=&quot;7&quot;<br />    &gt;  </b><!--colorc--></span><!--/colorc--><br /><br /><br />现在保存这个文本文件,扩展名得是.src。还需要为插件准备一个图标文件。这个图标得是16x16像素的gif、jpg、jpge或png文件,文件名必须和插件代码的名字一致。比如,我这个代码文件叫chinaunix.src,那么它的图标文件就得是chinaunix.gif或 chinaunix.png什么的。详细要求在<a href="http://mycroft.mozdev.org/deepdocs/iconinfo.html" target="_blank">这里</a>。<br /><br />在把你的插件提交到Mycroft之前,请遵照 <a href="http://mycroft.mozdev.org/quality.html" target="_blank">这里的要求</a>检查一番吧。怎么<a href="http://mycroft.mozdev.org/deepdocs/installing.html" target="_blank">安装</a>你的插件呢?最简单的办法,直接copy到Mozilla的searchplugins目录。默认情况下,Windows 下这个目录是C:/Program Files/Mozilla.org/Mozilla/searchplugins(Firefox的是C:/Program Files/Mozilla Firefox/searchplugins),Linux下是/usr/lib/Mozilla/searchplugins(非root用户需要写权 限)。<br /><br />一切正常?只要你满意就可以<a href="http://mycroft.mozdev.org/submit.html" target="_blank">提交</a>了,分享你的成果吧!

wolfg 发表于 2006-2-19 15:42

安装searchplughacks这个扩展可以方便地删除你不想使用的searchplugin

xiaowm 发表于 2006-2-19 18:05

<!--quoteo(post=15534:date=2006年2月19日 3&#58;42 PM:name=wolfg)--><div class='quotetop'>引用 (wolfg @ 2006年2月19日 3&#58;42 PM) <a href="index.php?act=findpost&pid=15534"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->安装searchplughacks这个扩展可以方便地删除你不想使用的searchplugin<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />可以不用扩展,直接在“searchplugins”目录内删除相应文件

wolfg 发表于 2006-2-19 20:54

<!--quoteo(post=15547:date=2006年2月19日 6&#58;05 PM:name=xiaowm)--><div class='quotetop'>引用 (xiaowm @ 2006年2月19日 6&#58;05 PM) <a href="index.php?act=findpost&pid=15547"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->可以不用扩展,直接在“searchplugins”目录内删除相应文件<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />呵呵,这个知道。

页: [1]

© 2004-2009 Mozest.com