Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var chromTag = {};
- chromTag.bookmarks = {};
- chromTag.folders = {};
- chromTag.tags = {};
- chromTag.init = function () {
- chrome.bookmarks.getTree(chromTag.bookmarkProcess);
- }
- chromTag.tagId = function(tag) {
- return tag.toLowerCase().replace(/ /g,'-').replace(/[^\w-]+/g,'');
- }
- chromTag.searchBookmark = function (folder,tag) {
- var searchResult = {};
- folder = typeof folder !== 'undefined' ? folder : '';
- tag = typeof tag !== 'undefined' ? tag : '';
- // do stuff
- return searchResult;
- }
- chromTag.bookmarkProcess = function(bookmarks) {
- for(var i=0; i < bookmarks.length; i++) {
- var bookmark = bookmarks[i];
- if (bookmark.url) {
- var bookmarkTags = {};
- var matchTags = bookmark.title.match(/\S*#(?:\[[^\]]+\]|\S+)/g);
- if(matchTags!=null) {
- for(var y=0; y < matchTags.length; y++) {
- var tag = matchTags[y].replace("#","").toLowerCase();
- bookmarkTags[y] = tag;
- if(typeof chromTag.tags[tag] === "undefined") {
- chromTag.tags[tag] = 1;
- } else {
- chromTag.tags[tag] = chromTag.tags[tag]+1;
- }
- }
- }
- chromTag.bookmarks[bookmark.id] = ({"id": bookmark.id, "folder": bookmark.parentId, "title": bookmark.title, "url": bookmark.url, "tags": bookmarkTags});
- }
- if (bookmark.children) {
- chromTag.folders[bookmark.id] = {"id": bookmark.id, "title": bookmark.title};
- chromTag.bookmarkProcess(bookmark.children);
- }
- }
- };
- chromTag.init();
- console.log(chromTag.bookmarks); // Return Object ... OK
- for(var item in chromTag.bookmarks) console.log(item); // Nothing :-()
Advertisement
Add Comment
Please, Sign In to add comment