当前位置: 动力学知识库 > 问答 > 编程问答 >

google chrome extension - How do i access every bookmark item in order to select\unselect them?

问题描述:

I am writing a Chrome Extension which opens all the user's bookmarks in tabs.

So far i've made the popup.html which opens in tabs the selected folder from the Bookmarks bar.

I'm making a settings page and i would like to know how can i access and display every single item of the user's Bookmarks in order to select a bookmark to exclude from opening with a checkbox.

In less words, i would like to:

Bookmarks bar

---> Bookmark1

---> Bookmark2 //display those bookmarks with a checkbox

---> Bookmark1

In order to have

Excluded bookmarks:

[x]Bookmark 1

[ ]Bookmark 2

[x]Bookmark 3

Thanks in advance

网友答案:

I wrote code to list the contents of a chrome user's bookmarks to the console.log:

The process_bookmark function prints the bookmarks

The chrome.browserAction.onClicked is called when the user clicks the extension button

function process_bookmark(bookmarks) {

    for (var i =0; i < bookmarks.length; i++) {
        var bookmark = bookmarks[i];
        if (bookmark.url) {
            console.log("bookmark: "+ bookmark.title + " ~  " + bookmark.url);
        }

        if (bookmark.children) {
            process_bookmark(bookmark.children);
        }
    }
}

chrome.browserAction.onClicked.addListener(function(tab) {
  console.log("listing bookmarks: " );
  chrome.bookmarks.getTree( process_bookmark );
});

Google's bookmark docs are here

分享给朋友:
您可能感兴趣的文章:
随机阅读: