-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
47 lines (41 loc) · 1.13 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var rAssist;
var bookmarksTree;
var RAsearches;
var markCount=0;
function setBookmarkRoot(callback) {
chrome.bookmarks.search({'title': 'Research Assist'}, function (tmp) {
if (tmp.length < 1) {
chrome.bookmarks.create({'title': 'Research Assist'},
function(newFolder) {
rAssistN = newFolder;
});
} else {
rAssistN = tmp[0]; //node is hopefully in the first slot here.
}
callback(rAssistN);
});
}
function getChildren(node) {
chrome.bookmarks.getChildren(node.id, function(bmNodes) {
for (var i=0; i<bmNodes.length; i++)
{
if (!bmNodes[i].url)
getChildren(bmNodes[i]);
else {
markCount++;
RAsearches.innerHTML += "<li> <a href='" + bmNodes[i].url + "' target='_blank'>" + bmNodes[i].title + " </a> </li>";
chrome.browserAction.setBadgeText({'text':markCount.toString()});
}
}
});
}
function init() {
RAsearches = document.getElementById("RAsearches");
setBookmarkRoot(function (rAssistNode) {
rAssist = rAssistNode;
getChildren(rAssist);
});
}
window.onload = function() {
init();
}