开发一个调用“另存为”的 Firefox 插件/附加组件来自FF自己的一套函数

发布于 2024-11-18 20:15:16 字数 596 浏览 7 评论 0原文

我有一个基本的 FF 插件,可以轮询 window.document 页面 DOM 中的某些内容。当它看到它时,它应该保存该页面。这是最困难的部分。我不想复制“保存完成”的功能,我只想在适当的时候从插件/插件中调用预先存在的功能。

这是 XPCom 的事情吗?或者是通过相关 API 的纯 JavaScript?

iMacros for Firefox 可以调用另存为(无需弹出相关的对话框),但我不知道如何。

任何人都可以建议如何调用像这样更深层次的 Firefox 函数吗?

谢谢,- Paul

PS - 我真的很喜欢 Mozilla 存档格式, MHT 和 Faithful Save 但我认为它再次复制了功能。我的另一种选择是调用它的函数,但这对我来说就像 Firefox 本机函数一样不透明。

I have a basic FF addon that polls for something in the DOM of the page in window.document. When it sees it, it is supposed to save the page. That's the hard part. I don't want to replicate the functionality of "save complete" I just want to call the pre-existing functionality from the plugin/addon at the right moment.

Is this an XPCom thing? Or is it pure JavaScript via the relevant APIs ?

iMacros for Firefox can invoke Save-as (without popping the associated dialog), but I can't see how.

Can anyone advise as to how to call deeper Firefox functions like this?

Thanks, - Paul

PS - I really love Mozilla Archive Format, with MHT and Faithful Save but I think it is replicating functionality again. My alternative is to invoke it's function, but that's as opaque to me as the firefox native one.

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

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

发布评论

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

评论(1

夕色琉璃 2024-11-25 20:15:16

您可以使用 nsIWebBrowserPersist.saveDocument() 来实现此目的:

var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
  createInstance(Ci.nsIWebBrowserPersist);
var localPath = Cc["@mozilla.org/file/local;1"].
  createInstance(Ci.nsILocalFile);
localPath.initWithPath(pathToLocalDirectory);
var localFile = localPath.clone();
localFile.append("mylocalfile.html");
persist.saveDocument(document, localFile, localPath, null, 0, 0);

关键是第三个参数,它指定链接的 URI 的存储位置。请参阅http://mxr.mozilla.org/mozilla2.0/source/embedding/components/webbrowserpersist/public/nsIWebBrowserPersist.idl#256 获取完整文档。

You can use nsIWebBrowserPersist.saveDocument() for this:

var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
  createInstance(Ci.nsIWebBrowserPersist);
var localPath = Cc["@mozilla.org/file/local;1"].
  createInstance(Ci.nsILocalFile);
localPath.initWithPath(pathToLocalDirectory);
var localFile = localPath.clone();
localFile.append("mylocalfile.html");
persist.saveDocument(document, localFile, localPath, null, 0, 0);

The key is the third parameter which specifies where the linked URIs should be stored. See http://mxr.mozilla.org/mozilla2.0/source/embedding/components/webbrowserpersist/public/nsIWebBrowserPersist.idl#256 for complete documentation.

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