无法在附加套件 API 中设置 Firefox 书签描述

发布于 2024-12-29 22:40:37 字数 352 浏览 1 评论 0原文

我找到了 nsINavBookmarksService ,但是从 Firefox 3 开始,它似乎没有任何用于获取/设置书签描述的 API 方法。 (API doc)

我见过其他附加组件修改描述为同步数据存储的方法(这正是我想要做的)。我猜测也许该描述是一个非 gecko 标准,这就是为什么它不被直接支持的原因,但是必须有一个完全不同的接口来操作我还没有发现的书签。

谁能帮忙解决这个新手问题吗?

I found the nsINavBookmarksService, however since Firefox 3, it does not seem to have any API methods for getting/setting the Bookmark description. (API doc)

I've seen other Add-Ons modify the description as a method of synchronized data storage (which is exactly what I'm trying to do). I'm guessing perhaps the description is a non-gecko standard, and that's why it is not directly supported, but then there must be a completely different interface for manipulating Bookmarks that I haven't discovered.

Can anyone help with this newbie problem?

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

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

发布评论

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

评论(1

若有似无的小暗淡 2025-01-05 22:40:37

从 Firefox 3 开始,书签已合并到包含所有浏览历史记录的位置数据库中。因此,要获取书签,请执行历史查询,如下所示(第一行是 特定于您似乎正在使用的附加 SDK):

var {Cc, Ci} = require("chrome");
var historyService = Cc["@mozilla.org/browser/nav-history-service;1"]
                       .getService(Ci.nsINavHistoryService);
var options = historyService.getNewQueryOptions();
var query = historyService.getNewQuery();
query.onlyBookmarked = true;

var result = historyService.executeQuery(query, options);
result.root.containerOpen = true;
for (var i = 0; i < result.root.childCount; i++)
{
  var node = result.root.getChild(i);
  console.log(node.title);
}

这与代码示例 此处。您的问题当然是 nsINavHistoryResultNode 无法存储像描述这样的数据。不过,您可以设置注释,请参阅使用地点注释服务。因此,如果您的书签已经有一个 node 变量:

var annotationName = "my.extension.example.com/bookmarkDescription";
var ioService = Cc["@mozilla.org/network/io-service;1"]
                  .getService(Ci.nsIIOService);
var uri = ioService.newURI(node.uri, null, null);
var annotationService = Cc["@mozilla.org/browser/annotation-service;1"]
                          .getService(Ci.nsIAnnotationService);
annotationService.setPageAnnotation(uri, annotationName,
     "Some description", 0, Ci.nsIAnnotationService.EXPIRE_NEVER);

供参考:nsIAnnotationService.setPageAnnotation()

Starting with Firefox 3 the bookmarks have been merged into the Places database containing all of your browsing history. So to get the bookmarks you do a history query, like this (first line is specific to the Add-on SDK which you appear to be using):

var {Cc, Ci} = require("chrome");
var historyService = Cc["@mozilla.org/browser/nav-history-service;1"]
                       .getService(Ci.nsINavHistoryService);
var options = historyService.getNewQueryOptions();
var query = historyService.getNewQuery();
query.onlyBookmarked = true;

var result = historyService.executeQuery(query, options);
result.root.containerOpen = true;
for (var i = 0; i < result.root.childCount; i++)
{
  var node = result.root.getChild(i);
  console.log(node.title);
}

That's mostly identical to the code example here. Your problem is of course that nsINavHistoryResultNode has no way of storing data like a description. You can set annotations however, see Using the Places annotation service. So if you already have a node variable for your bookmark:

var annotationName = "my.extension.example.com/bookmarkDescription";
var ioService = Cc["@mozilla.org/network/io-service;1"]
                  .getService(Ci.nsIIOService);
var uri = ioService.newURI(node.uri, null, null);
var annotationService = Cc["@mozilla.org/browser/annotation-service;1"]
                          .getService(Ci.nsIAnnotationService);
annotationService.setPageAnnotation(uri, annotationName,
     "Some description", 0, Ci.nsIAnnotationService.EXPIRE_NEVER);

For reference: nsIAnnotationService.setPageAnnotation()

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