开发Firefox扩展最简单的方法是什么? [英] What is the easiest way to develop Firefox extension?

查看:129
本文介绍了开发Firefox扩展最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算开发一个简单的Firefox扩展,它将缩短当前活动选项卡的URL,显示一个带有缩短URL的弹出窗口,并将其放置到剪贴板中。



在Google Chrome中,这将非常简单(根据 http://developer.chrome .com / extensions / getstarted.html ) - 纯粹的JavaScript加上一些JavaScript API与浏览器UI的交互调用。



然而,在搜索了一个好的Firefox扩展教程后,我发现了最正式的链接:
$ b



据他们说,即使是与浏览器的用户界面进行最简单的交互,我也必须学习XUL语言。最重要的是,我将不得不设置自定义的Firefox配置文件,以免在开发过程中使用默认的配置文件,创建复杂的目录结构,在不明确的XML中编写清单,找出如何打包和测试我实现的任何内容等。 / p>

2013年,是不是有一个更简单的方法来构建Firefox扩展?

解决方案


2013年,还有没有更容易的方法来构建Firefox扩展?


是的!

在这个问题上是令人难以置信的过时的。有一种新的,更好的开发Firefox扩展的方式 - Firefox插件SDK

然而,偶然发现它是相当困难的通过只是谷歌搜索Firefox附加教程的线路。我很惊讶Mozilla不会更积极地宣传它,或者至少在您发现的那些网页上提及。



开始的步骤 (Mac / Linux,但应该与PC非常相似): b
$ b


  • https://addons.mozilla.org/en-US/developers/builder ,解压缩。

  • 快速浏览README文件(总是有用的)。
  • 从SDK执行 source bin / activate dir执行 cfx docs - 此bootstraps的本地副本 SDK文档并在浏览器中打开它。

  • 离开SDK dir,为您的扩展名创建一个空的目录。
  • 执行 cfx init 里面扩展名目录 - 这将产生所有必要的文件/目录。

  • 按照 Getting-started-with-cfx 页面:


    • 更新 lib / main.js ,只需几行JS即可将自定义小部件放置到附加栏上。 >
    • 执行 cfx run - 这会打开全新的Firefox实例,并带有新的闪亮扩展名。

    • 模块将小部件放置在导航栏上而不是加载项栏上,在大约50行JavaScript中开发全功能的扩展。


      HTH!

      更新



      有一个新的标准叫做 WebExtensions



      From MDN


      目前是用于开发Firefox附加组件的几个工具集,但WebExtensions将在2017年底成为标准。



      如果您要编写一个新的附加组件, >我们建议您编写WebExtension 。



      I'm planning to develop a simple Firefox extension that will shorten URL of a currently active tab, display a popup with the shortened URL, and place it into the clipboard.

      In Google Chrome, this would be pretty easy (according to http://developer.chrome.com/extensions/getstarted.html) -- pure JavaScript plus a few calls to JavaScript API-s of interacting with the browser's UI.

      However, after searching around for a good Firefox extensions tutorial, the most officially-looking links I found are:

      According to them, it looks like I will have to learn the XUL language for even the simplest interactions with the browser's UI. On top of that, I will have to set up custom Firefox profile so as not to hose my default profile during development, create complicated directory structure, write manifest in obscure XML, figure out how to package and test whatever I implement, etc.

      It's 2013, isn't there an easier way of building Firefox extensions?

      解决方案

      It's 2013, isn't there an easier way of building Firefox extensions?

      Yes there is!

      The links you provided in the question are unbelievably outdated. There is a new, much better way of developing Firefox extensions -- Firefox Add-on SDK.

      However it's pretty hard to stumble upon it by just googling along the lines of 'firefox addon tutorial'. I'm amazed Mozilla doesn't advertise it more aggressively, or at least mention it on those pages you found.

      Steps to get started (Mac/Linux, but should be pretty similar for PC):

      • Download the SDK from https://addons.mozilla.org/en-US/developers/builder, unpack it.
      • Quickly glance over the README file (always useful).
      • Execute source bin/activate from the SDK dir (the same dir the README file is in).
      • Execute cfx docs -- this bootstraps local copy of SDK docs and opens it in your browser.
      • Leave the SDK dir, create an empty dir for your extension.
      • Execute cfx init inside the extensions dir -- this generates all the necessary files/directories.
      • Follow the rest of getting-started-with-cfx page:
        • Update lib/main.js with just a few lines of JS to place a custom widget onto add-on bar.
        • Execute cfx run -- this opens fresh Firefox instance with your new shiny extension in it.

      All in all, it took me just a few hours to read the documentation, get familiar with the SDK API-s, find SDK module to place a widget onto a navigation bar instead of add-on bar, and develop fully-functional extension in just about 50 lines of JavaScript.

      HTH!

      Update

      There is a new standard, called WebExtensions

      From MDN

      There are currently several toolsets for developing Firefox add-ons, but WebExtensions will become the standard by the end of 2017.

      If you are writing a new add-on, we recommend that you write a WebExtension.

      这篇关于开发Firefox扩展最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆