Fixed the issue with multiple layers of folders and giving correct node.url to the new window object.

This commit is contained in:
Jonathan Kempf 2014-07-25 20:28:14 -04:00
parent 085913a03b
commit 3d6125a681
5 changed files with 39 additions and 40 deletions

0
LICENSE Normal file → Executable file
View file

6
README.md Normal file → Executable file
View file

@ -1,5 +1,3 @@
This is Forked from a great, simple extension from **[@ryanmcgrath](http://twitter.com/ryanmcgrath)** from **[here](https://github.com/ryanmcgrath/takeoff)**.
Takeoff
---------------------------------------------------------------------------
I was up late one night, and my brain was in one of those modes where I needed
@ -15,8 +13,8 @@ run with it as you see fit. MIT licensed.
To Install
----------------------------------------------------------------------------
Download it, unzip it somewhere, load it up in your **[extensions tab](chrome://extensions/)** by loading
an "unpacked" extension. Or, just drag and drop...easy. NOTE: You must enable developer tools to get this to work.
Download it, unzip it somewhere, load it up in your extensions tab by loading
an "unpacked" extension.
Publicity
---------------------------------------------------------------------------

4
manifest.json Normal file → Executable file
View file

@ -1,10 +1,10 @@
{
"name": "Takeoff",
"version": "1.0",
"version": "2.0",
"description": "Takeoff grabs a random entry from your Bookmarks collection and loads it when you start the browser or open a new tab.",
"chrome_url_overrides": {
"newtab": "takeoff.html"
},
"manifest-version": 2,
"manifest_version": 2,
"permissions": ["tabs", "bookmarks"]
}

35
takeoff.html Normal file → Executable file
View file

@ -3,40 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>
<script>
var bookmarks = {
walk: function(tree) {
var flattened = [];
if(typeof tree.children !== 'undefined') {
flattened.concat(tree.children);
} else {
tree.forEach(function(node) {
if(typeof node.children !== 'undefined') {
flattened = flattened.concat(node.children);
} else {
flattened = flattened.concat(walkBookmarkTree(node));
}
});
}
return flattened;
},
setPage: function(windowObj) {
chrome.bookmarks.getTree(function(bookMarksArr) {
var flattendBookmarks = bookmarks.walk(bookMarksArr[0].children),
bookmark = flattendBookmarks[Math.floor(Math.random() * flattendBookmarks.length)];
chrome.tabs.getSelected(windowObj.windowId, function(tab) {
chrome.tabs.update(tab.id, {url: bookmark.url});
});
});
},
};
chrome.windows.getLastFocused(bookmarks.setPage);
</script>
<script src="takeoff.js" type="text/javascript"></script>
</head>
</body>
</html>

34
takeoff.js Normal file
View file

@ -0,0 +1,34 @@
var marks = [];
chrome.bookmarks.getTree(function(itemTree){
itemTree.forEach(function(item){
processNode(item);
});
});
function processNode(node) {
// recursively process child nodes
if(node.children) {
node.children.forEach(function(child) {
processNode(child);
});
}
// print leaf nodes URLs to console
if(node.url) {
console.log(node.url);
var book = marks.push(node.url);
}
}
function setPage(windowObj) {
bookmark = marks[Math.floor(Math.random() * marks.length)];
chrome.tabs.getSelected(windowObj.windowId, function(tab) {
chrome.tabs.update(tab.id, {url: bookmark});
});
}
chrome.windows.getLastFocused(setPage);