Takeoff, a Chrome extension to randomly load bookmarks

This commit is contained in:
Ryan McGrath 2011-02-11 02:06:22 -08:00
commit 709b4ce3ce
4 changed files with 95 additions and 0 deletions

42
takeoff.html Normal file
View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<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>
</head>
</body>
</html>