Download the Google Chrome root bookmarks folder

I am trying to write a better bookmark manager in Chrome extensions. The problem is that there are no simple examples (which I can find) on how to actually use the bookmarks API .

I looked at the source of the example (when I d / led and installed it on my computer, he did nothing but provide a search box. Entering / entering text and clicking on return could not do anything) and can not find anything useful .

My ultimate goal is to make an extension that allows me to save pages so that they come and read later without having to go to an account on any service somewhere. Therefore, I plan to create one or two folders of folders in the root folder / other bookmarks - at least in the "unread pages" folder. In this folder I will create unread bookmarks. When a user marks an item as read, it will be deleted from this folder.

So what I'm trying to do ... any help would be greatly appreciated, even if it just points to some good examples.

UPDATE:

 ...<script> function display(tree){ document.getElementById("Output").innerHTML = tree; } function start(){ chrome.bookmarks.getTree(display); } </script> </head> <body> <h4 id="Output"></h4> <script> start(); </script> ... 

This displays [object Object] , which suggests (at least to me with limited experience with JavaScript) that the object exists. But how to access members of this object?

Changing tree to tree.id or any other of the displayed display options is undefined .

+6
javascript google-chrome google-chrome-extension bookmarks
source share
3 answers

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.

+9
source share

Bookmarks are organized in the form of a tree, where each node in the tree is a bookmark or group (a folder may contain nodes). Each node in the tree is represented by a BookmarkTreeNode Object.

There is no root bookmark folder in the sense of a file system object. All bookmarks are stored in a structured file, accessed through the api in the link you specified. The root of the tree is returned by getTree:

 chrome.bookmarks.getTree 
+1
source share

Ok, I found out how to access what I want. In retrospect, I should have seen this before.

http://code.google.com/chrome/extensions/tut_debugging.html

Using the debugger, I was able to set a breakpoint and view objects. [object Object] - an array of length 1.

Using the function in my example, tree [0] .children is an array containing children. There are two children in my default settings tree, tree [0] .children [0] is the “bookmarks bar” and tree [0] .children [1] is “Other bookmarks”. The rest of the bookmark tree flows from there, although Other bookmarks (tree [0] .children [1]) is the folder I'm looking for.

+1
source share

All Articles