Firefox bookmarks exploration not going past first level with Javascript

后端 未结 2 1341
野性不改
野性不改 2021-01-16 11:47

I\'ve written some code to explore my Firefox bookmarks but I only get the first level of bookmarks (i.e. I don\'t get the links in the folders).

e.g.

相关标签:
2条回答
  • 2021-01-16 12:28

    Just to save time to anyone who want to get all the bookmarks, do not do query.setFolders([ bookmarksService.bookmarksMenuFolder, bookmarksService.toolbarFolder, bookmarksService.unfiledBookmarksFolder ], 3); as suggested by Wladimir since it WON'T bring you all of the bookmarks but instead do an intersect of the folders and only give u the bookmarks which are placed at all of those folders, as written at Mozilla doc's

    You can set multiple folders and the result will be the intersection of all the folders.

    ( https://developer.mozilla.org/en/Querying_Places )

    0 讨论(0)
  • 2021-01-16 12:38

    One obvious mistake is using toolbarFolder as a starting point - that's only the bookmarks toolbar. If you want all bookmarks (meaning bookmarks menu, bookmarks toolbar and unsorted bookmarks) you need to change query parameters:

    query.setFolders([
        bookmarksService.bookmarksMenuFolder,
        bookmarksService.toolbarFolder,
        bookmarksService.unfiledBookmarksFolder
    ], 3);
    

    The other issue is getting childCount property on a nsINavHistoryResultNode object - there is no such property. Before you can access properties of nsINavHistoryContainerResultNode you need to call QueryInterface, either explicitly or implicitly (via instanceof). So I would write:

    } else if (node.type == 6 && node instanceof Components.interfaces.nsINavHistoryContainerResultNode) {
        var oldOpen = node.containerOpen;
        node.containerOpen = true;
        browse_bookmark_node(node, array);
        node.containerOpen = oldOpen;
    }
    
    0 讨论(0)
提交回复
热议问题