forked from iplanwebsites/newtab-bookmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Chrome bookmarks fetching from collection and now the fetchin…
…g will update existing URLs and remove deleted ones (related to issue iplanwebsites#5)
- Loading branch information
Showing
12 changed files
with
172 additions
and
130 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Chrome bookmarks fetcher | ||
* | ||
* @info: Collection of helper functions | ||
* | ||
*/ | ||
/*global require:true, define:true, chrome: true */ | ||
|
||
define([ | ||
"jquery", | ||
"underscore", | ||
"instances/all-bookmarks" | ||
], | ||
function( $, _, allBookmarks ) { | ||
"use strict"; | ||
|
||
var chromeAdapter = { | ||
|
||
fetch: function() { | ||
return this.importChromeBookmarks(); | ||
}, | ||
|
||
importChromeBookmarks: function() { | ||
var def = new $.Deferred(), | ||
self = this; | ||
|
||
chrome.bookmarks.getTree(function( tree, folder ) { | ||
self.parseChromeBookmarkTree( tree, folder, def ); | ||
}); | ||
def.done(function() { | ||
var unkeptBookmarks = allBookmarks.filter(function( model ) { | ||
if ( model.get('type') !== 'chrome' ) { | ||
return false; | ||
} | ||
return !model.get('keep'); | ||
}); | ||
|
||
// Delete models who've been removed from Chrome bookmarks | ||
_.each( unkeptBookmarks, function( model ) { | ||
model.destroy(); | ||
}); | ||
}); | ||
|
||
return def.promise(); | ||
}, | ||
|
||
// Recurse over the bookmarks tree | ||
parseChromeBookmarkTree: function( tree, folder, def ) { | ||
var self = this, | ||
folder = folder || []; | ||
|
||
_.each( tree, function( node ) { | ||
if ( node.children && node.children.length > 0 ) { | ||
//it's a folder | ||
var path = _.uniq( folder ); | ||
if ( node.title ) { | ||
//add the folder name to the list | ||
path.push( node.title ); | ||
} | ||
// Recurse over the subtree | ||
self.parseChromeBookmarkTree( node.children, path ); | ||
} else { | ||
//it's a URL | ||
self.addChromeBookmark( node, folder ); | ||
} | ||
}); | ||
|
||
def && def.resolve(); | ||
}, | ||
|
||
addChromeBookmark: function( bookmark, folder ) { | ||
var actual = allBookmarks.where({ url: bookmark.url })[0], | ||
data = { | ||
title : bookmark.title, | ||
url : bookmark.url, | ||
id : bookmark.id, | ||
type : 'chrome', | ||
dateAdded : bookmark.dateAdded, | ||
folder : folder, | ||
keep : true // mark this model to be kept | ||
}; | ||
|
||
// Add or update collection | ||
if ( actual ) { | ||
actual.set( data ); | ||
} else { | ||
allBookmarks.add( data ); | ||
} | ||
|
||
} | ||
}; | ||
|
||
return chromeAdapter; | ||
}); |
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 +1 @@ | ||
<input type="range" min="0" max="100" id="zoom_level" value="50" /> | ||
<input type="range" min="0" max="100" id="zoom_level" value="50" /> |
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
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,10 +1,10 @@ | ||
{ | ||
"name" : "NewTab-Bookmarks", | ||
"version" : "0.0.1", | ||
"private" : true, | ||
"dependencies" : {}, | ||
"devDependencies" : { | ||
"grunt-contrib" : "0.3.0", | ||
"grunt-smushit" : "0.3.7" | ||
} | ||
} | ||
"name": "NewTab-Bookmarks", | ||
"version": "0.0.1", | ||
"private": true, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"grunt-contrib": "*", | ||
"grunt": "~0.3" | ||
} | ||
} |
Oops, something went wrong.