Takeoff, a Chrome extension to randomly load bookmarks
This commit is contained in:
commit
709b4ce3ce
4 changed files with 95 additions and 0 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2009 - 2010 Ryan McGrath
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
23
README.md
Normal file
23
README.md
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
Takeoff
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
To Install
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
Download it, unzip it somewhere, load it up in your extensions tab by loading
|
||||||
|
an "unpacked" extension.
|
||||||
|
|
||||||
|
Publicity
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Email: ryan [at] venodesigns dot net
|
||||||
|
Twitter: **[@ryanmcgrath](http://twitter.com/ryanmcgrath)**
|
||||||
|
Web: **[Veno Designs - Personal Site](http://venodesigns.net/)**
|
||||||
9
manifest.json
Normal file
9
manifest.json
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "Takeoff",
|
||||||
|
"version": "1.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"
|
||||||
|
},
|
||||||
|
"permissions": ["tabs", "bookmarks"]
|
||||||
|
}
|
||||||
42
takeoff.html
Normal file
42
takeoff.html
Normal 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>
|
||||||
Reference in a new issue