我已經寫了一些代碼來探索我的Firefox書籤,但我只獲得第一級的書籤(即我沒有得到文件夾中的鏈接)。Firefox書籤探索不會超過第一級使用Javascript
例如
Search_engines/
- yahoo.com
google.com
在這個例子中我只有Search_engines訪問和google.com不是雅虎.com
我的函數是遞歸的我不知道爲什麼會發生這種情況。
我的代碼:
function browse_bookmark_node(bookmark_node, array)
{
// We explore the bookmarks with this function
// iterate over the immediate children of this folder
for (var i = 0; i < bookmark_node.childCount; i ++) {
var node = bookmark_node.getChild(i);
if (node.type ==0) {
// the node is a link so we add it to the array
array.push(node.title);
} else if (node.type ==6) {
// the node is a folder so we explore it
browse_bookmark_node(node, array);
}
}
}
function wrapper_browse_bookmark_node(bookmark_node) {
// We use this function to wrapp the function browse_bookmark_node and keep track of the links
var array = [];
browse_bookmark_node(bookmark_node, array);
return array;
}
// All the code following is used to access firefox bookmarks and works fine
var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService);
var options = historyService.getNewQueryOptions();
var query = historyService.getNewQuery();
var bookmarksService = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService);
var bookmarksMenuFolder = bookmarksService.bookmarksMenuFolder;
query.setFolders([bookmarksMenuFolder], 1);
var result = historyService.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
// The function call to explore the bookmarks
var links_array = wrapper_browse_bookmark_node(rootNode);
// close a container after using it!
rootNode.containerOpen = false;
@Wladimir Palant非常感謝您的回答。在閱讀我的代碼後,我意識到它有一個錯字! – Bruno 2011-06-07 12:23:00