开发一个非常简单的浏览器扩展

发布于 2024-11-30 03:04:39 字数 508 浏览 5 评论 0原文

我正在寻求开发浏览器扩展。

安装此扩展后,它将告诉浏览器在来自特定域列表的所有页面加载中包含一个 javascript 文件。

这种类型的扩展被 Google Chrome 称为“内容脚本”。

据我所知,要为 Chrome 创建这种类型的扩展,您只需将此代码放入 “Manifest”文件

{
  "name": "My extension",
  ...
  "content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "js": ["jquery.js", "myscript.js"]
    }
  ],
  ...
}

一旦安装了扩展,jquery.js 和 myscripts.js 将包含在 google.com 的每个页面加载中

Chrome 采用的这种扩展开发方法似乎非常简单。

我的问题是,为其他主要浏览器复制这种类型的扩展有多困难?

I'm looking to developing a browser extension.

This extension once installed will tell the browser to include a javascript file on all page loads from a list of specific domains.

This type of extension is called "Content Scripts" by Google Chrome.

From what I read, to create this type of extensions for Chrome you simply put this code in
"Manifest" File

{
  "name": "My extension",
  ...
  "content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "js": ["jquery.js", "myscript.js"]
    }
  ],
  ...
}

Once the extension is installed jquery.js and myscripts.js will be included on every page load of google.com

This approach to extension development adopted by Chrome seems really easy.

My question is how difficult would it be to replicate this type of extension for the other major browsers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酸甜透明夹心 2024-12-07 03:04:39

Firefox 本身不提供加载内容脚本的简单方法。但是,GreaseMonkey 插件 可以,并且有大量示例脚本可供选择在 http://userscripts.org/ 上。除此之外,GreaseMonkey 脚本可以编译成不再需要的“真正的”扩展 GreaseMonkey,它们也可以安装在 Chrome 中(无需扩展)。

Firefox 的另一种可能性是使用 Add-on Builder 或 SDKpage-mod 模块< /a>.像这样的东西应该可以工作:

var pageMod = require("page-mod");

pageMod.PageMod({
  include: ["http://www.google.com/*"],
  contentScriptFile: [data.url("jquery.js"), data.url("myscript.js")]
});

使用附加构建器,应该很容易将此代码转换为实际的扩展。不过,我没有使用附加 SDK 的经验,因此无法为您提供任何其他帮助。

Firefox itself doesn't provide a simple way to load content scripts. However, the GreaseMonkey add-on does and there is a large collection of example scripts to choose from on http://userscripts.org/. Add to this that GreaseMonkey scripts can be compiled into a "real" extension that no longer needs GreaseMonkey, and they can be installed in Chrome as well (without needing an extension).

Another possibility for Firefox is using the Add-on Builder or SDK and the page-mod module. Something like this should work:

var pageMod = require("page-mod");

pageMod.PageMod({
  include: ["http://www.google.com/*"],
  contentScriptFile: [data.url("jquery.js"), data.url("myscript.js")]
});

With the Add-on Builder it should be fairly easy to turn this code into an actual extension. I have no experience with the Add-on SDK however and so I cannot offer you any additional help.

好多鱼好多余 2024-12-07 03:04:39

尝试 Kango 框架。这是一个跨浏览器扩展框架。您可以使用单一源代码为所有主要浏览器开发扩展。支持 IE、Firefox、Chrome、Opera 和 Safari。

Try Kango Framework. This is a cross-browser extensions framework. You can develop extensions for all major browsers working with single source code. Supports IE, Firefox, Chrome, Opera and Safari.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文