forked from niutech/chrome-devtools-sidebar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookmarks.js
21 lines (20 loc) · 800 Bytes
/
bookmarks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function update(tree) {
var ul = document.getElementById('bookmarks');
ul.innerHTML = render(tree[0].children);
ul.addEventListener('click', function(e) {
if(e.target.classList.contains('folder')) {
e.target.classList.toggle('open');
return false;
}
});
}
function render(tree) {
var html = '';
tree.forEach(function(i) {
html += '<li><a href="' +
(i.url ? i.url + '" target="_top"><img src="http://www.google.com/s2/favicons?domain=' + (i.url.match(/:\/\/(.[^/]+)/)||[,'example.com'])[1] + '">' : '#" class="folder">') +
i.title.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') + '</a>' +
(i.children && i.children.length ? '<ul>' + render(i.children) + '</ul>' : '') + '</li>';
});
return html;
}