firefox扩展插件制作方法



插件地址:http://bbs.blueidea.com/thread-2798570-1-1.html


http://www.yoursblog.cn/blueideasearch.xpi

首先第一步 说一下怎么样查看firefox插件的源码, 就我上边写的那个东西,把它下载下来.将它的扩展名改为zip并解压。会得到一个blueideaserach的文件夹, 这个文件夹中便是我做的这个插件的源码 firefox扩展插件制作方法_第1张图片

这个目录中除了 chrome目录  chrome.manifest install.rdf  这三个以外都不是必须的。

chrome.manifest   这个文件中是对所有文件的一个列表.

install.rdf             这个是安装信息的描述.

chrome目录中放的是主程序.  


这个整个目录结构是这样的.

     blueideasearch-----
           --------chrome
                    -----content
                               --overlay.xul
                               --overlay.js
            --------chrome.manifest
            ---------install.rdf


也就是说 只要按这个目录结构建好. 并压缩成 zip包 改名为 xpi  它便可以在firefox中安装了.

overlay.xul 文件中是对插件的人UI描述。
overlay.js   是程序的处理部分.


下边这个代码是install.rdf中的,他是安装信息描述。

  1.       <?xml version="1.0"?>
  2. <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  3.      xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  4.   <Description about="urn:mozilla:install-manifest">
  5.     <em:id>[email protected]</em:id>
  6.     <em:version>1.0</em:version>
  7.     <em:type>2</em:type>
  8.    
  9.     <!-- Target Application this extension can install into,
  10.          with minimum and maximum supported versions. -->
  11.     <em:targetApplication>
  12.       <Description>
  13.         <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
  14.         <em:minVersion>1.5</em:minVersion>
  15.         <em:maxVersion>2.0.0.*</em:maxVersion>
  16.       </Description>
  17.     </em:targetApplication>
  18.    
  19.     <!-- Front End MetaData -->
  20.     <em:name>blueidea search</em:name>
  21.     <em:description>blueidea </em:description>
  22.     <em:creator>yaba</em:creator>
  23.     <em:homepageURL>http://bbs.blueidea.com/</em:homepageURL>
  24.         <em:iconURL>chrome://blueideasearch/content/logo.gif</em:iconURL>
  25.         <em:updateURL>http://www.yoursblog.cn/bibar_update.rdf</em:updateURL>
  26.   </Description>      
  27. </RDF>

复制代码


chrome.manifest文件列表描述内容

  1. content     blueideasearch    chrome/content/
  2. overlay  chrome://browser/content/browser.xul chrome://blueideasearch/content/overlay.xul

复制代码

install.rdf中

  1.     <Description>
  2.         <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
  3.         <em:minVersion>1.5</em:minVersion>
  4.         <em:maxVersion>2.0.0.*</em:maxVersion>
  5.       </Description>

复制代码


这个em:id是不能变的. 他指明了这个插件的使用对像为 firefox.

em:minVersion 为最低可以安装这个插件的版本 。maxVersion反之.


  1.     <em:name>blueidea search</em:name>
  2.     <em:description>blueidea </em:description>
  3.     <em:creator>yaba</em:creator>
  4.     <em:homepageURL>http://bbs.blueidea.com/</em:homepageURL>
  5.     <em:iconURL>chrome://blueideasearch/content/logo.gif</em:iconURL>
  6.     <em:updateURL>http://www.yoursblog.cn/bibar_update.rdf</em:updateURL>

复制代码

   em:name 是插件的名称。
   em:description  描述
   em:creator      作者
   em:homepageURL  主页
   em:iconURL     图标地址
   em:updateURL       查找更新地址


了解了上边的内容,就可以进行插件的编写了.  firefox它本身是基于Mozilla 框架开发的。

大家可以在FF的地址栏输入以下地址 chrome://browser/content/browser.xul  来看一下 FF的本身自己的UI的描述

在这里推荐大家用fireBug 来查看.. 可以清楚看到浏览器的DOM结构. 我们以后的操作都要针对这个DOM结构.

大家看到我们说要对插件UI描述的文件扩展名为.xul  对这xul语言 大家可以参考http://www.xulplanet.com/  这个网站..它里有XUL详细介绍。把它理解成一种HTML就可以了. 他的语法标记十分简单易懂。
   

  1.        <toolbarbutton id="home-button" class="toolbarbutton-1 chromeclass-toolbar-additional" label="主页" ondragover="nsDragAndDrop.dragOver(event, homeButtonObserver);" ondragdrop="nsDragAndDrop.drop(event, homeButtonObserver);" ondragexit="nsDragAndDrop.dragExit(event, homeButtonObserver);" onclick="BrowserHomeClick(event);"/>
  2.    
复制代码

   
   这对FF上  对 "主页" 这个按钮的描述。

   

  1.      <textbox sizetopopup="pref" id="urlbar" flex="1" chromedir="ltr" type="autocomplete" autocompletesearch="history" autocompletepopup="PopupAutoComplete" completeselectedindex="true" tabscrolling="true" showcommentcolumn="true" enablehistory="true" oninput="gBrowser.userTypedValue = this.value" ontextentered="return handleURLBarCommand(param);" ontextreverted="return handleURLBarRevert();"><deck id="page-proxy-deck" onclick="PageProxyClickHandler(event);"><image id="page-proxy-button" ondraggesture="PageProxyDragGesture(event);" tooltiptext="拖放此图标以创建到此页面的链接"/><image id="page-proxy-favicon" validate="never" ondraggesture="PageProxyDragGesture(event);" onload="this.parentNode.selectedIndex = 1;                                 event.stopPropagation();" onerror="gBrowser.addToMissedIconCache(this.src);                                  this.removeAttribute('src');                                  this.parentNode.selectedIndex = 0;" tooltiptext="拖放此图标以创建到此页面的链接"/></deck><hbox id="urlbar-icons"><button type="menu" style="-moz-user-focus: none;" class="plain" id="feed-button" chromedir="ltr" onclick="return FeedHandler.onFeedButtonClick(event);"><menupopup position="after_end" onpopupshowing="return FeedHandler.buildFeedList(this);" oncommand="return FeedHandler.subscribeToFeed(null, event);" onclick="checkForMiddleClick(this, event);"/></button><image tooltiptext="显示此窗口的安全性信息" id="lock-icon" onclick="if (event.button == 0) displaySecurityInfo(); event.stopPropagation();"/><image id="safebrowsing-urlbar-icon" tooltiptext="此页面可能具有危险性;点击查看详细信息。" level="safe" onclick="goDoCommand('safebrowsing-show-warning')"/></hbox></textbox>
  2.      
复制代码


   这是对FF“地址栏”描述


大家看是不是特别像HTML.

我们开始写插件的UI吧 。。

     打开\chrome\content\overlay.xul 文件.
   

  1.      <?xml version="1.0"?>
  2.       <overlay id="bisearch" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  3.      <script src="chrome://blueideasearch/content/overlay.js" />
  4.    
复制代码


     <overlay id="bisearch" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 就理解成.在写HTML时加入的那一句声明吧.
    <script src="chrome://blueideasearch/content/overlay.js" /> 这是程序的处理部份.  就像在写HTML是引入JS一样.
   哧哧,是不是越来越像在写网页了.

    我们要确定插件要出现的位置. 比如我们的插件要出现在地址栏下边. 我们可以用FireBug来查看刚才我给的那个chrome的地址. 找到地址栏,并查看它的父结点.
    这里我查到地址栏的父结点为<toolbox id="navigator-toolbox">
    我们就这样写:  
   

  1.          <toolbox id="navigator-toolbox">
  2.         <toolbaritem id="bdSearchBoxbar">
  3.                 <toolbarbutton id="bisearch_button" tooltiptext="转到蓝色理想" image="chrome://blueideasearch/content/blueidea.png" oncommand="GotoWebSite('http://bbs.blueidea.com');"></toolbarbutton>
  4.                 </toolbaritem>
  5.           </toolbox>
  6.    
复制代码


     这个代码呢..是在<toolbox id="navigator-toolbox">下追加一个子节点 toolbarbutton 是一个按钮   oncommand是它的一个事件,当按下它时触发这个事件. 里边的响应的函数就在我们一开始引入的那个JS里.


  1.       /**
  2. * 在当前窗口中打开链接。
  3. */

  4. function GotoWebSite(url){
  5.        
  6.         loadURI(url)
  7.        
  8. }
  9.   
复制代码

IE插件又是怎么做的.和FF一样吗

IE的就麻烦了.要写ActiveX了. 还是firefox的扩展性强啊,而且容易上手。只需要掌握XUL和JS就可以搞了~


研究数年,我已经做出了广泛使用的火狐扩展了,全世界都在用。如果不是你的警告导致楼主不敢参数我的非技术讨论可能发布要更早!建议总管理员撤销上面是非不分的小管理员。

我写的火狐自动表单扩展:
https://addons.mozilla.org/zh-CN/firefox/addon/fillforms/

开发日志:
http://blog.csdn.net/sysdzw/article/details/5514062

用 greasemonkey(firefox的一个扩展),很方便做一些web外挂和脚本化处理的东西
也支持转xpi方便安装

你可能感兴趣的:(firefox扩展插件制作方法)