How Firefox Can Bookmark Custom Bookmarks

I am writing a Firefox add-on code that manages user bookmarks.

I started with the Bookmark Search code from https://developer.mozilla.org/En/Places_Developer_Guide and ended up writing the following code that works ...

var folders = [bookmarksService.bookmarksMenuFolder, bookmarksService.toolbarFolder, bookmarksService.unfiledBookmarksFolder]; var bookmarks = []; for (var i = 0; i < 3; i++) { query.setFolders([folders[i]], 1); var result = historyService.executeQuery(query, options); var rootNode = result.root; rootNode.containerOpen = true; getNode(rootNode, bookmarks); rootNode.containerOpen = false; } 

The problem with this code is that it hardcodes 3 folders by default. I would like the code to handle the case when the user created their own folder folders.

How can this code be changed so that it moves across all bookmark folders?

+4
source share
1 answer

I think you're confused with the terminology "folder" here. The three hard-coded elements that you have in your code block are all you need. Any bookmarks created by the user will be located in one of these three places. You can see this in action by opening the bookmark editor in Firefox (Ctrl + Shift + B). In the tree area on the left, select the All bookmarks element and note that under it there are only 3 (possibly 4) elements:

  • Bookmarks Bar
  • Bookmark Menu
  • Unsorted bookmarks

If you right-click the top-level item "All bookmarks", you will notice that there is no "Create Folder" option at this level. Any user-created bookmarks below the sub-items listed at this level.

The site developer guide contains one additional top-level folder ( tagsFolder ), but I don’t think you need to worry about that. I cannot imagine an existing bookmark, and not in one of three other places.

+2
source

Source: https://habr.com/ru/post/1413031/


All Articles