-
Notifications
You must be signed in to change notification settings - Fork 0
/
bkmrks.js
78 lines (59 loc) · 1.94 KB
/
bkmrks.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
class Bkmrks {
constructor() {
chrome.storage.sync.get({
theme: '2196F3',
favicons: true
}, (userPreferenceItems) => {
const userThemeColor = userPreferenceItems.theme;
const showFavicons = userPreferenceItems.favicons;
chrome.bookmarks.getTree((chromeBookmarks) => {
let appContainer = document.getElementById('app');
const userThemeCss = `
#app > li > h1 {
background: #${userThemeColor};
}
li li h1 {
color: #${userThemeColor};
}
`;
if(!showFavicons) {
appContainer.className = 'no-favicon';
}
const bookmarkList = chromeBookmarks[0].children[0].children;
if(bookmarkList.length > 0) {
appContainer.innerHTML = `<style>${userThemeCss}</style> ${this.renderBookmarks(bookmarkList, showFavicons)}`;
} else {
appContainer.innerHTML = `
<h1>You have no bookmarks :(</h1>
<p>To use this extension, please add some bookmarks to Chrome.</p>
`;
}
});
});
}
renderBookmarks(bookmarkList, showFavicons) {
let returnString = '';
for(let bookmark of bookmarkList) {
if(bookmark.children) {
returnString += `
<li class="sublist-title">
<h1>${bookmark.title}</h1>
<ul>${this.renderBookmarks(bookmark.children, showFavicons)}</ul>
</li>`;
} else {
returnString += `
<li class="link-item">
<a style="background-image:url(${showFavicons ? this.getFaviconUrl(bookmark.url) : ''});" href="${bookmark.url}">
<span>${bookmark.title}</span>
</a>
</li> `;
}
}
return returnString;
}
getFaviconUrl(rawUrl) {
return `http://www.google.com/s2/favicons?domain=${rawUrl.split('/')[0]}//${rawUrl.split('/')[2]}/`;
}
}
const bkmrks = new Bkmrks();