rotten77

Chrome Bookmarks

Nov 20th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var chromTag = {};
  2.     chromTag.bookmarks = {};
  3.     chromTag.folders = {};
  4.     chromTag.tags = {};
  5.  
  6. chromTag.init = function () {
  7.     chrome.bookmarks.getTree(chromTag.bookmarkProcess);
  8. }
  9.  
  10. chromTag.tagId = function(tag) {
  11.     return tag.toLowerCase().replace(/ /g,'-').replace(/[^\w-]+/g,'');
  12. }
  13.  
  14.  
  15. chromTag.searchBookmark = function (folder,tag) {
  16.     var searchResult = {};
  17.     folder = typeof folder !== 'undefined' ? folder : '';
  18.     tag = typeof tag !== 'undefined' ? tag : '';
  19.  
  20.     // do stuff
  21.     return searchResult;
  22. }
  23.  
  24. chromTag.bookmarkProcess = function(bookmarks) {
  25.     for(var i=0; i < bookmarks.length; i++) {
  26.  
  27.         var bookmark = bookmarks[i];
  28.  
  29.         if (bookmark.url) {
  30.             var bookmarkTags = {};
  31.             var matchTags = bookmark.title.match(/\S*#(?:\[[^\]]+\]|\S+)/g);
  32.  
  33.             if(matchTags!=null) {
  34.                 for(var y=0; y < matchTags.length; y++) {
  35.                     var tag = matchTags[y].replace("#","").toLowerCase();
  36.                     bookmarkTags[y] = tag;
  37.  
  38.                     if(typeof chromTag.tags[tag] === "undefined") {
  39.                         chromTag.tags[tag] = 1;
  40.                     } else {
  41.                         chromTag.tags[tag] = chromTag.tags[tag]+1;
  42.                     }
  43.                 }
  44.             }
  45.  
  46.             chromTag.bookmarks[bookmark.id] = ({"id": bookmark.id, "folder": bookmark.parentId, "title": bookmark.title, "url": bookmark.url, "tags": bookmarkTags});
  47.         }
  48.  
  49.         if (bookmark.children) {
  50.             chromTag.folders[bookmark.id] = {"id": bookmark.id, "title": bookmark.title};
  51.             chromTag.bookmarkProcess(bookmark.children);
  52.         }
  53.     }
  54. };
  55.  
  56. chromTag.init();
  57. console.log(chromTag.bookmarks); // Return Object ... OK
  58.  
  59. for(var item in chromTag.bookmarks) console.log(item); // Nothing :-()
Advertisement
Add Comment
Please, Sign In to add comment