There is currently no good way to find folders such as "Other Bookmarks" or "Bookmarks Bar" in the bookmarks API. You will need to iterate over all bookmarks and find which nodes have these root folders and save your bookmark id. Bug fixed Problem 21330 .
The root identifier is always 0, and when I mean 0, it matches Bookmarks and Other Bookmarks. Like any tree structure, each node has children. If you want to get all bookmarks in one folder, you can use the getChildren API and get each node recursively (you can do it iteratively). For example, the following bookmark will receive each bookmark:
printBookmarks('0'); function printBookmarks(id) { chrome.bookmarks.getChildren(id, function(children) { children.forEach(function(bookmark) { console.debug(bookmark.title); printBookmarks(bookmark.id); }); }); }
Now, why should we call the API for each iteration? This is the API to get the whole tree. If you try this, you will see that each node in getTree will have a list of children. It's fine:
chrome.bookmarks.getTree(function(bookmarks) { printBookmarks(bookmarks); }); function printBookmarks(bookmarks) { bookmarks.forEach(function(bookmark) { console.debug(bookmark.id + ' - ' + bookmark.title + ' - ' + bookmark.url); if (bookmark.children) printBookmark(bookmark.children); }); }
That's all, you can do it all iteratively, but it's better, but you can understand it :) Please note that since you want to redo the bookmarks bar, you can redefine this page in extensions (coming soon): http: // code. google.com/chrome/extensions/override.html
If you want to show a good HTML tree for your bookmarks, you can easily do this by extending the getTree function shown above to accept the parent DOM. You can do something like this . Modify the code to use getTree or collapse everything and use getChildren and get more bookmarks if they request it.
Mohamed mansour
source share