A
A
Alexey Yarkov2015-10-10 19:44:49
JavaScript
Alexey Yarkov, 2015-10-10 19:44:49

How to get all Google Chrome bookmarks in background.js?

You need to get the entire bookmark tree from Google Chrome. In the background.js file, when the menu item is clicked, I try to display this tree, but nothing comes out. Who faced? Help.
Now I do this:

function normalizeChromiumTime(t) {
    return ((t - 11644473600000000) / 1000000);
}

function recursiveJSON2ARRAY(obj, parent){
  $.each(obj, function(i, v){
    if(v.children && 'object' === typeof v.children && Object.keys(v.children).length){
      var parentname = v.name;
      $.each(v.children, function(i, child){
        if(child.url){
          var date_added = normalizeChromiumTime(child.date_added);
          marks.data.push({
            parentname: parent+'->'+parentname, 
            date: date_added, 
            name: child.name, 
            url: child.url
          });
        }
        else{
          recursiveJSON2ARRAY(v.children, parent+"->"+parentname);
        }
      });
    }
    else{
      if(v.url){
        var date_added = normalizeChromiumTime(v.date_added);
        marks.data.push({
          parentname: parent, 
          date: date_added,  
          name: v.name, 
          url: v.url
        });
      }
    }
  });
}

function getAllBookmarks(tree){
  // запускаем парсер закладок
  $.each(tree, function(i, childrenElement){
    if(childrenElement.children && 'object' === typeof childrenElement.children){
      recursiveJSON2ARRAY(childrenElement.children, childrenElement.name);
    }
  });
  alert(JSON.stringify(marks.data));
}


chrome.bookmarks.getTree(getAllBookmarks);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2015-10-11
@yarkov

Just like that, everyone rushed to help)))
Okay, he himself decided through crutches as usual. Solution here: freelanceronline.ru/categories/javascript/kak-udal...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question