This repository has been archived on 2026-03-31. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
takeoff/takeoff.html

42 lines
984 B
HTML

<!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>