用于了解页面何时被添加书签/下载的事件侦听器
有什么方法可以跟踪 Firefox 中页面被添加书签或下载的时间吗?我 意思是是否有任何事件在书签或 下载页面?我正在使用 Add-on SDK 来开发 Add-on。
如果没有,请建议我一些解决方法。
Is there any way to track when a page is bookmarked or downloaded in Firefox? I
mean is there any event that is triggered on bookmarking or
downloading a page? I am using Add-on SDK for developing Add-on.
If not, then kindly suggest me some workarounds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器窗口具有被触发的
元素当用户添加书签或下载页面时。前者的ID为Browser:AddBookmarkAs
,后者的ID为Browser:SavePage
。附加 SDK 本身不允许您访问它们,因此您需要使用chrome
包直接访问 XPCOM。像这样的事情:此代码未经测试,因此可能存在小问题,但总体概念应该是正确的。
编辑:实际上,如果您使用内部
window-utils
包,似乎同样更简单。但不确定该包提供的 API 是否稳定。The browser window has
<command>
elements that get triggered when the user bookmarks or downloads a page. The former has IDBrowser:AddBookmarkAs
, the latterBrowser:SavePage
. The Add-on SDK itself doesn't give you access to them, so you need to use thechrome
package to access XPCOM directly. Something like this:This code isn't tested so there might be minor issues but the overall concept should be correct.
Edit: Actually, the same seems to be simpler if you use the internal
window-utils
package. Not sure whether the API provided by this package is stable however.全部在addon sdk文档中。尽管我必须承认我第一次并没有看到它。
https://addons .mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/tutorials/event-targets.html
以下示例来自文档。
请注意,我必须将 Cr 添加到 require 中才能使其正常工作,
并在generateQI() 调用中用 Ci 替换 Components.interfaces。
It is all in the addon sdk documentation. Although I must admit I did not see it the first time around.
https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/tutorials/event-targets.html
The following example is from the documentation.
Note that I had to add Cr to the require to make it work
as well as substitute Components.interfaces by Ci in the generateQI() call.