bookmarks.getTree()

这篇翻译不完整。请帮忙从英语翻译这篇文章

bookmarks.getTree() 返回一个数组,该数组每一项为bookmarks.BookmarkTreeNode对象,作为书签树的根节点。

如果它们是文件夹的话,你可以通过其children属性及其后代的children属性递归地访问整个树。

这是一个异步的函数,返回Promise

使用格式

var gettingTree = browser.bookmarks.getTree()

参数

无。

返回值

Promise对象,该对象未来会得到一个填充代表根节点的bookmarks.BookmarkTreeNode对象的数组。

浏览器兼容性

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No 45.0 No 33

示例

这个示例会打印出整个书签树:

function makeIndent(indentLength) {
  return ".".repeat(indentLength);
}

function logItems(bookmarkItem, indent) {
  if (bookmarkItem.url) {
    console.log(makeIndent(indent) + bookmarkItem.url);
  } else {
    console.log(makeIndent(indent) + "Folder");
    indent++;
  }
  if (bookmarkItem.children) {
    for (child of bookmarkItem.children) {
      logItems(child, indent);
    }
  }
  indent--;
}

function logTree(bookmarkItems) {
  logItems(bookmarkItems[0], 0);
}

function onRejected(error) {
  console.log(`An error: ${error}`);
}

var gettingTree = browser.bookmarks.getTree();
gettingTree.then(logTree, onRejected);

Acknowledgements

This API is based on Chromium's chrome.bookmarks API. This documentation is derived from bookmarks.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

文档标签和贡献者

 此页面的贡献者: trto1987
 最后编辑者: trto1987,