This commit is contained in:
KempfCreative 2014-07-26 00:48:42 +00:00
commit c3a9c1c1d2
5 changed files with 48 additions and 48 deletions

0
LICENSE Normal file → Executable file
View file

24
README.md Normal file → Executable file
View file

@ -1,23 +1,21 @@
Takeoff
Takeoff 2.0
---------------------------------------------------------------------------
I was up late one night, and my brain was in one of those modes where I needed
a new, really quick project to distract myself from what I was currently working
on. Sometimes that kind of thing helps the brain to get to a better solution.
Several years ago, I started separating out my browser behavior.
I noticed someone on Reddit by the name of [hokku was looking for an extension](http://www.reddit.com/r/AskReddit/comments/fjb0v/is_there_a_chrome_extension_that_can_set_my/)
to randomly choose a bookmark and load it on new tab/window instances. I took
20 minutes and knocked this together. It's open source, as I have zero interest
in maintaining it; feel free to learn from it to build your own, or fork it and
run with it as you see fit. MIT licensed.
Firefox was for fun, Chrome was for development. As a result, whenever I came across something interesting or educational, I would bookmark it in Chrome. This turned into folders of folders of development info, assets, blogs, and more. While these bookmarks were well organized, I found myself forgetting what bookmarks I had saved or what I had even saved them for.
"If they were so important," I asked myself, "I should remind myself what they were doing there in the first place." It was with this in mind that I began the search for an extension that would randomly load a bookmark and show it to me when I generated a new tab. This apparently didn't exist, so after Googling for a bit, I found a **[reddit post](http://www.reddit.com/r/AskReddit/comments/fjb0v/is_there_a_chrome_extension_that_can_set_my/)** that claimed to have solved this exact problem. The developer Ryan McGrath **[@ryanmcgrath](http://twitter.com/ryanmcgrath)** had created an extension, called "Takeoff", which I have now updated to work with any levels of folder structure and given an update to actually work with latest Chrome versions. (It was over 4 years old after all).
I plan on uploading this to the Google Chrome extensions store, but in the meantime, if you want to go ahead and fork it for other browsers, or whatever, please feel free, it is MIT Licensed after all.
To Install
----------------------------------------------------------------------------
Download it, unzip it somewhere, load it up in your extensions tab by loading
an "unpacked" extension.
an "unpacked" extension. Will also be in Chrome Extensions soon.
Publicity
---------------------------------------------------------------------------
Email: ryan [at] venodesigns dot net
Twitter: **[@ryanmcgrath](http://twitter.com/ryanmcgrath)**
Web: **[Veno Designs - Personal Site](http://venodesigns.net/)**
Email: kempfjj [at] gmail dot com
Twitter: **[@kempfcreative](http://twitter.com/kempfcreative)**
Web: **[KempfCreative - Personal Site](http://www.kempfcreative.com/)**

3
manifest.json Normal file → Executable file
View file

@ -1,9 +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,
"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);