-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ahmadassaf/master
Sync with main repo
- Loading branch information
Showing
12 changed files
with
1,760 additions
and
635 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,63 @@ | ||
var foldersList = [], urls = []; | ||
var booklight = function booklight() { | ||
|
||
chrome.bookmarks.getTree(function(bookmarksTree) { | ||
var booklight = this; | ||
|
||
foldersList = filterRecursively(bookmarksTree, "children", function(node) { | ||
if (node.url) urls.push(node); | ||
return !node.url && node.id > 0; | ||
}).sort(function(a, b) { | ||
// The sort functions make sure that we will have the last used folders on top | ||
return b.dateGroupModified - a.dateGroupModified; | ||
}); | ||
this.foldersList = []; | ||
this.urls = []; | ||
|
||
this.getBookmarks = function() { | ||
|
||
chrome.storage.local.set({"booklight": foldersList }, function(bookmarks) { console.log("Setting the folders list into the local storage !!") }); | ||
chrome.storage.local.set({"urls": urls }, function(bookmarks) { console.log("Setting the urls list into the local storage !!") }); | ||
chrome.bookmarks.getTree(function(bookmarksTree) { | ||
|
||
}); | ||
booklight.foldersList = filterRecursively(bookmarksTree, "children", function(node) { | ||
if (node.url) booklight.urls.push(node); | ||
return !node.url && node.id > 0; | ||
}).sort(function(a, b) { | ||
// The sort functions make sure that we will have the last used folders on top | ||
return b.dateGroupModified - a.dateGroupModified; | ||
}); | ||
|
||
// Recursively filter the passed TreeNodes | ||
function filterRecursively(nodeArray, childrenProperty, filterFn, results) { | ||
chrome.storage.local.set({"booklightFolders": booklight.foldersList }, function(bookmarks) { console.log("Setting the folders list into the local storage !!") }); | ||
chrome.storage.local.set({"booklightUrls": booklight.urls }, function(bookmarks) { console.log("Setting the urls list into the local storage !!") }); | ||
|
||
}); | ||
|
||
results = results || []; | ||
// Recursively filter the passed TreeNodes | ||
function filterRecursively(nodeArray, childrenProperty, filterFn, results) { | ||
|
||
results = results || []; | ||
|
||
nodeArray.forEach( function( node ) { | ||
if (filterFn(node)) results.push({title: node.title, id: node.id, dateGroupModified: node.dateGroupModified, folder: isLeaf(node), parentId: node.parentId}); | ||
if (node.children) filterRecursively(node.children, childrenProperty, filterFn, results); | ||
}); | ||
return results; | ||
}; | ||
|
||
// Check if the current bookmark is a leaf (does not contain more folders) | ||
function isLeaf(node) { | ||
var leafyNodes = []; | ||
node.children.forEach(function(child){ | ||
if (!child.hasOwnProperty('children')) leafyNodes.push(1); | ||
}); | ||
var isLeaf = leafyNodes.length == node.children.length ? true : false; | ||
return isLeaf; | ||
} | ||
} | ||
|
||
nodeArray.forEach( function( node ) { | ||
if (filterFn(node)) results.push({title: node.title, id: node.id, dateGroupModified: node.dateGroupModified, folder: isLeaf(node), parent: node.parentId}); | ||
if (node.children) filterRecursively(node.children, childrenProperty, filterFn, results); | ||
}); | ||
return results; | ||
}; | ||
this.attachListeners = function() { | ||
|
||
function isLeaf(node) { | ||
var leafyNodes = []; | ||
node.children.forEach(function(child){ | ||
if (!child.hasOwnProperty('children')) leafyNodes.push(1); | ||
}); | ||
var isLeaf = leafyNodes.length == node.children.length ? true : false; | ||
return isLeaf; | ||
chrome.runtime.onMessage.addListener(function(request, sender, sendrequest) { | ||
if (request.message == "booklight") { | ||
console.log("adding: " + request.url + " title: " + request.title + " to folder id: " + request.folder); | ||
chrome.bookmarks.create({ 'parentId': request.folder, 'title': request.title, 'url': request.url }); | ||
sendrequest({message: "success"}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
chrome.runtime.onMessage.addListener( | ||
function(request, sender, sendrequest) { | ||
if (request.message == "booklight") { | ||
console.log("adding: " + request.url + " title: " + request.title + " to folder id: " + request.folder); | ||
chrome.bookmarks.create({ 'parentId': request.folder, 'title': request.title, 'url': request.url }); | ||
sendrequest({message: "success"}); | ||
} | ||
}); | ||
var booklight = new booklight(); | ||
|
||
booklight.attachListeners(); | ||
booklight.getBookmarks(); |
Oops, something went wrong.