Fixed the issue with multiple layers of folders and giving correct node.url to the new window object.
This commit is contained in:
parent
085913a03b
commit
3d6125a681
5 changed files with 39 additions and 40 deletions
34
takeoff.js
Normal file
34
takeoff.js
Normal 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);
|
||||
Reference in a new issue