Files
I2P_in_Private_Browsing_Mod…/bookmarks.js

143 lines
3.7 KiB
JavaScript
Raw Normal View History

2023-06-20 10:37:28 -04:00
async function createI2PToolbar(bookmarkToolbar) {
const ibbt = await browser.bookmarks.search("I2P Toolbar");
2019-11-11 21:02:38 -05:00
2023-06-20 10:37:28 -04:00
async function onToolbarCreated(node) {
const ibt = await browser.bookmarks.search("I2P Toolbar");
await bookmarks(ibt[0]);
}
2019-11-11 21:02:38 -05:00
2023-06-20 10:37:28 -04:00
async function setupDir(ibbt) {
if (!ibbt.length) {
const createBookmark = await browser.bookmarks.create({
title: "I2P Toolbar",
parentId: bookmarkToolbar.id,
});
await onToolbarCreated(createBookmark);
}
}
2019-11-11 21:02:38 -05:00
2023-06-20 10:37:28 -04:00
await setupDir(ibbt);
}
2019-11-11 21:02:38 -05:00
2023-06-20 10:37:28 -04:00
async function bookmarks(bookmarkToolbar) {
const controlHost = control_host();
const controlPort = control_port();
2019-11-11 21:38:38 -05:00
2023-06-20 10:37:28 -04:00
async function createBookmark({ url, title, parentId }) {
const createRhizomeBookmark = await browser.bookmarks.create({
url,
title,
parentId,
});
console.log("Bookmarked", createRhizomeBookmark);
}
2020-03-18 00:15:46 -04:00
2023-06-20 10:37:28 -04:00
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,
});
}
}
2019-11-11 21:02:38 -05:00
2023-06-20 10:37:28 -04:00
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,
});
2023-06-20 10:37:28 -04:00
}
}
2020-06-22 21:49:14 -04:00
2023-06-20 10:37:28 -04:00
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,
});
}
}
2023-06-20 10:37:28 -04:00
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,
});
}
}
2023-06-20 10:37:28 -04:00
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,
});
2019-11-24 04:25:06 -05:00
}
2023-06-20 10:37:28 -04:00
}
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",
});
2023-06-20 10:37:28 -04:00
await createI2PToolbar(bookmarkToolbar[0]);
}
2020-12-03 12:20:43 -05:00
function conditionalBookmarksSetup(obj) {
2022-10-24 19:57:51 -04:00
console.log("(bookmarks) state", obj.bookmarks_state);
if (obj.bookmarks_state == false) {
2020-12-03 12:20:43 -05:00
bookmarksSetup();
}
if (obj.bookmarks_state == undefined) {
2020-12-03 12:20:43 -05:00
bookmarksSetup();
2019-11-24 04:25:06 -05:00
}
}
2020-12-03 12:20:43 -05:00
if (browser != null) {
2021-09-30 16:46:20 -04:00
if (browser.windows != undefined) {
2022-10-24 19:57:51 -04:00
let gettingStorage = browser.storage.local.get("bookmarks_state");
2021-09-30 16:46:20 -04:00
gettingStorage.then(conditionalBookmarksSetup, bookmarksSetup);
}
}
2022-10-24 19:57:51 -04:00
const bookmarksButton = document.getElementById("bookmarksButton");
2020-12-03 12:20:43 -05:00
if (bookmarksButton != null) {
2022-10-24 19:57:51 -04:00
bookmarksButton.addEventListener("click", bookmarksSetup);
}