【问题标题】:extension components to get visit count in firefox's history and bookmarks?扩展组件以获取 Firefox 历史记录和书签中的访问次数?
【发布时间】:2014-03-23 14:43:44
【问题描述】:

我想知道在firefox的bookmarkshistory中可以使用哪个接口来获取每个link的访问次数,用于开发扩展

我尝试使用nav-history-service 获取书签和历史记录的链接,但不知道如何查看访问次数。

【问题讨论】:

标签: javascript firefox firefox-addon xpcom gecko


【解决方案1】:

此代码将遍历前 10 个书签条目。如果它是一个 url,它会检查它的 .accessCount 属性,该属性包含它被访问的次数。

var hs = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);

var query = hs.getNewQuery();
var options = hs.getNewQueryOptions();

// Query users bookmarks, not history
options.queryType = options.QUERY_TYPE_BOOKMARKS;
// Execute the search and store results
var result = hs.executeQuery(query, options);

// Open the root containerNode and open it
var resultContainerNode = result.root;
// OPEN resultContainerNode
resultContainerNode.containerOpen = true;
// Search results are now child items of this container?
for (var i = 0; i < resultContainerNode.childCount; ++i) {
    var childNode = resultContainerNode.getChild(i);
    if (childNode.type == childNode.RESULT_TYPE_URI) {
        console.log('childNode ' + i + ' is url = ', childNode)
        console.log('times visited = ', childNode.accessCount)
    }
    if (i >= 10) {
        break
    }
}

// CLOSE resultContainerNode
resultContainerNode.containerOpen = false;

要点在这里:https://gist.github.com/Noitidart/9729440

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-07
    • 2013-11-18
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多