Thanks for the response. It's definitely a messy API for a simple
usecase. here's the solution I went with:
function collectFoldersAsTags(bookmark, tags, callback) {
if (bookmark.parentId) {
chrome.bookmarks.get(bookmark.parentId, function(results) {
var mark = results[0];
tags.push(mark.title);
collectFoldersAsTags(mark, tags, callback);
});
} else {
callback(tags);
}
}
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
if (bookmark.url) {
collectFoldersAsTags(bookmark, [], function(tags) {
alert(tags.join(' '));
});
}
});
On Dec 15, 12:09 am, Marcos Aruj <[email protected]> wrote:
> Maybe something like this:
>
> function bookmarkFoldersAsTags(aTags, aBookmark) {
> if (!aTags)
> aTags = [];
>
> if (!aBookmark.parentId)
> return;
>
> function getBookmarkCallback(aResults) {
> var mark = aResults[0];
> aTags.push(mark.title);
> bookmarkFoldersAsTags(aTags, mark);
> }
> chrome.bookmarks.get(aBookmark.parentId, getBookmarkCallback);
>
> }
>
> I just wrote it here without trying and I haven't used the bookmarks API
> yet. Just used the code you provided and tweaked it a bit to be recursive.
> You should end up with the aTags array filled with your tags, which you may
> join later. Hopefully this helps, or maybe someone else has a better/working
> alternative.
>
> Good night!
>
>
>
>
>
> On Mon, Dec 14, 2009 at 11:07 PM, Ryan <[email protected]> wrote:
> > I'm trying to navigate from my bookmark listener to the root node and
> > collect all of the folder hierarchy, but the bookmarks API uses async
> > callbacks which is quite difficult to work with.
>
> > This code doesn't work because the while loop is stuck in an infinite
> > loop and the callback does not interupt the loop correctly. Is there
> > some other way?
>
> > ex:
> > function bookmarkFoldersAsTags(bookmark) {
> > var tags = [];
>
> > var mark = bookmark;
> > while (mark.parentId) {
> > chrome.bookmarks.get(mark.parentId, function(results) {
> > mark = results[0];
> > tags.push(mark.title);
> > });
> > }
> > return tags.join(' ');
> > }
>
> > chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
> > if (bookmark.url) {
> > console.debug(bookmarkFoldersAsTags(bookmark));
> > }
> > });
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<chromium-extensions%2Bunsu
> > [email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/chromium-extensions?hl=en.
>
> --
> Marcos Aruj Alvarez
> Ingeniero de Software
> -------------------------------
> [email protected]
> -----
--
You received this message because you are subscribed to the Google Groups
"Chromium-extensions" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/chromium-extensions?hl=en.