能够在 Firefox 中加载初始化脚本吗?

Ability to load init script in Firefox?

我长期以来一直使用 Conkeror 作为我的默认 Web 浏览器,并习惯了 configuring/adding 我的浏览器使用 js 代码和所有 XUL Api 到 .conkerorrc 的新功能] 文件。我正在迁移到 Firefox,因为它有更好的支持并且由 Mozilla 积极维护。但是,我一直缺少的功能之一是点文件,我可以轻松地配置我喜欢的任何东西,通过 git 备份所有这些文件并直接评估代码(使用 Mozrepl)同时我正在编码以查看结果。

有什么方法可以 inject/execute Firefox 启动时的脚本,例如 ~/.firefox/index.js

现有 Firefox 中没有执行用户在启动时提供的 JavaScript 代码的功能。像这样的功能已经 requested of Firefox since 2006-04-02

在任何不同的 Firefox 附加组件类型中编写附加组件都是微不足道的 (XUL/Overlay, Restartless/Bootstrap, Add-on SDK, or WebExtensions) which would run whatever JavaScript you desire upon Firefox startup. This could be done to either run code that was included in the add-on (simple), or that runs the JavaScript contained in a file that is loaded from a location external to the add-on (more complex). Which add-on type you used to implemented this would impact which interfaces you had available within the code you write. One drawback of writing your own extension which runs code included in the add-on is that in order to use it with a release, or beta version of Firefox is that you would need to have it signed by Mozilla。虽然这是一个快速简单的过程,但它确实会增加一些额外的开销 development/test循环.

您没有在问题中指定任何 firefox-addon 标签。此外,您还没有描述您想要的功能,除非是概括性的。您的问题似乎也不是要询问您将如何实施此类附加组件。考虑到这些以及已经有多个附加组件实现了用户提供的 运行 任意 JavaScript(包括 XUL)代码的功能,我不打算在这里提供执行此操作的代码功能。

但是,如果您有兴趣使用现有的附加组件,这里有几个选项:

  • userChromeJS: This extension was derived from the code originally provided as an example of how to implement the functionality requested in bug 332529。它列出的第一个功能是: "Complete chrome customization is possible by running custom javascript code or overlaying chrome with .xul overlays." 这是一个基于 Overlay 的附加组件,您可以使用它来使用 XUL。这听起来像是您有兴趣获得的功能。
  • uc: "A userChromeJS clone with built-in subscript/overlay loader capability."
  • Greasemonkey: "Customize the way a web page displays or behaves, by using small bits of JavaScript." This is a commonly used add-on which permits writing more complex JavaScript code. The code is executed in a sandbox,不在扩展范围内。这样做是出于安全原因。
  • Custom Style Script (Inject desired CSS or JS): "Add Custom JavaScript Codes or Styles (CSS) to an specific page or all pages."