-
Notifications
You must be signed in to change notification settings - Fork 10
/
bookmarks.js
142 lines (124 loc) · 3.68 KB
/
bookmarks.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
async function createI2PToolbar(bookmarkToolbar) {
const ibbt = await browser.bookmarks.search("I2P Toolbar");
async function onToolbarCreated(node) {
const ibt = await browser.bookmarks.search("I2P Toolbar");
await bookmarks(ibt[0]);
}
async function setupDir(ibbt) {
if (!ibbt.length) {
const createBookmark = await browser.bookmarks.create({
title: "I2P Toolbar",
parentId: bookmarkToolbar.id,
});
await onToolbarCreated(createBookmark);
}
}
await setupDir(ibbt);
}
async function bookmarks(bookmarkToolbar) {
const controlHost = control_host();
const controlPort = control_port();
async function createBookmark({ url, title, parentId }) {
const createRhizomeBookmark = await browser.bookmarks.create({
url,
title,
parentId,
});
console.log("Bookmarked", createRhizomeBookmark);
}
async function createHomeBookmark() {
const bookmarkItems = await browser.bookmarks.search({
title: "I2P Extension Home Page",
});
if (!bookmarkItems.length) {
await createBookmark({
url: browser.runtime.getURL("home.html"),
title: "I2P Extension Home Page",
parentId: bookmarkToolbar.id,
});
}
}
async function createTorrentBookmark() {
const bookmarkItems = await browser.bookmarks.search({
title: "Bittorrent",
});
if (!bookmarkItems.length) {
await createBookmark({
url: `http://${controlHost}:${controlPort}/i2psnark`,
title: "Bittorrent",
parentId: bookmarkToolbar.id,
});
}
}
async function createConsoleBookmark() {
const bookmarkItems = await browser.bookmarks.search({
title: "I2P Console",
});
if (!bookmarkItems.length) {
await createBookmark({
url: `http://${controlHost}:${controlPort}/home`,
title: "I2P Console",
parentId: bookmarkToolbar.id,
});
}
}
async function createMailBookmark() {
const bookmarkItems = await browser.bookmarks.search({
title: "Web Mail",
});
if (!bookmarkItems.length) {
await createBookmark({
url: `http://${controlHost}:${controlPort}/webmail`,
title: "Web Mail",
parentId: bookmarkToolbar.id,
});
}
}
async function createI2PTunnelBookmark() {
const bookmarkItems = await browser.bookmarks.search({
title: "Hidden Services Manager",
});
if (!bookmarkItems.length) {
await createBookmark({
url: `http://${controlHost}:${controlPort}/i2ptunnel`,
title: "Hidden Services Manager",
parentId: bookmarkToolbar.id,
});
}
}
await createHomeBookmark();
await createTorrentBookmark();
await createI2PTunnelBookmark();
await createMailBookmark();
await createConsoleBookmark();
defaultSettings.bookmarks_state = true;
}
async function bookmarksSetup() {
const gettingInfo = await browser.runtime.getPlatformInfo();
if (gettingInfo.os === "android") {
return;
}
const bookmarkToolbar = await browser.bookmarks.search({
query: "Toolbar",
});
await createI2PToolbar(bookmarkToolbar[0]);
}
function conditionalBookmarksSetup(obj) {
console.log("(bookmarks) state", obj.bookmarks_state);
if (obj.bookmarks_state == false) {
bookmarksSetup();
}
if (obj.bookmarks_state == undefined) {
bookmarksSetup();
}
}
if (browser != null) {
if (browser.windows != undefined) {
let gettingStorage = browser.storage.local.get("bookmarks_state");
gettingStorage.then(conditionalBookmarksSetup, bookmarksSetup);
}
}
const bookmarksButton = document.getElementById("bookmarksButton");
if (bookmarksButton != null) {
bookmarksButton.addEventListener("click", bookmarksSetup);
}