-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (64 loc) · 2.03 KB
/
script.js
File metadata and controls
82 lines (64 loc) · 2.03 KB
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
79
80
81
82
const columns = [];
chrome.bookmarks.getTree((items) => {
const bookmarksBar = items[0].children.find((x) =>
options.ROOT_FOLDER.test(x.title)
);
if (!bookmarksBar) {
console.error(`Was expecting a folder called '${options.ROOT_FOLDER}'`);
}
const rootBookmarks = bookmarksBar.children.filter(
(node) => !node.children
);
const rootFolders = bookmarksBar.children.filter((node) => !!node.children);
const rootColumn = {
title: "/",
children: [],
};
rootBookmarks.forEach((node) => addBookmark(rootColumn, node));
columns.push(rootColumn);
rootFolders.forEach((node) => {
const column = {
title: node.title,
children: [],
};
visit(column, node);
columns.push(column);
});
render(columns);
});
const visit = (column, node, path = []) => {
if (node.children) {
node.children.forEach((x) => visit(column, x, [...path, node.title]));
return;
}
addBookmark(column, node, path);
};
const addBookmark = (column, node, path = []) => {
if (!node.url || node.url.startsWith("javascript:")) {
// ignore bookmarklets
return;
}
const isSeparator =
options.SEPARATORS.includes(node.title) || node.type === "separator";
column.children.push({
title: node.title,
url: node.url,
path: path,
isSeparator,
});
};
document.addEventListener("DOMContentLoaded", () => {
document.body.style.background = options.BACKGROUND;
document.getElementById("welcome").style.color = options.TITLE_COLOR;
});
// notify firefox users to set their home page
if (window.browser) {
window.browser.runtime.getBrowserInfo().then((browser) => {
if (browser.name === "Firefox") {
console.log(
`Hello, friend. On ${browser.name} you can make this your home page by setting the following URL in your home page preferences:`
);
console.log(window.location.href);
}
});
}