Files
I2P_in_Private_Browsing_Mod…/bookmarks.js
2019-11-11 21:39:35 -05:00

147 lines
4.7 KiB
JavaScript

function bookmarks(bookmarkToolbar) {
console.log("Setting up bookmark toolbar", bookmarkToolbar);
function bookHome(bookmarkItems) {
if (!bookmarkItems.length) {
function gotProxyInfo(info) {
let host = info.value.http.split(":")[0];
let port = info.value.http.split(":")[1];
if (port == "7644") {
var createBookmark = browser.bookmarks.create({
url: "about:I2p",
title: "Home Page",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
} else {
var createBookmark = browser.bookmarks.create({
url: "http://localhost:7657",
title: "Home Page",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
}
console.log("(bookmarks) adding home page bookmark");
}
console.log("(bookmarks) checking if we're running in an I2P Browser");
var gettingInfo = browser.proxy.settings.get({});
gettingInfo.then(gotProxyInfo);
}
}
function bookTorrent(bookmarkItems) {
if (!bookmarkItems.length) {
function gotProxyInfo(info) {
let host = info.value.http.split(":")[0];
let port = info.value.http.split(":")[1];
if (port == "7644") {
var createBookmark = browser.bookmarks.create({
url: "http://localhost:7647/i2psnark",
title: "Bittorrent",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
} else {
var createBookmark = browser.bookmarks.create({
url: "http://localhost:7657/i2psnark",
title: "Bittorrent",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
}
}
console.log("(bookmarks) checking if we're running in an I2P Browser");
var gettingInfo = browser.proxy.settings.get({});
gettingInfo.then(gotProxyInfo);
}
}
function bookMail(bookmarkItems) {
if (!bookmarkItems.length) {
function gotProxyInfo(info) {
let host = info.value.http.split(":")[0];
let port = info.value.http.split(":")[1];
if (port == "7644") {
var createBookmark = browser.bookmarks.create({
url: "http://localhost:7647/webmail",
title: "Web Mail",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
} else {
var createBookmark = browser.bookmarks.create({
url: "http://localhost:7657/webmail",
title: "Web Mail",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
}
console.log("(bookmarks) adding webmail bookmark");
}
console.log("(bookmarks) checking if we're running in an I2P Browser");
var gettingInfo = browser.proxy.settings.get({});
gettingInfo.then(gotProxyInfo);
}
}
function bookI2PTunnel(bookmarkItems) {
if (!bookmarkItems.length) {
function gotProxyInfo(info) {
let host = info.value.http.split(":")[0];
let port = info.value.http.split(":")[1];
if (port == "7644") {
var createBookmark = browser.bookmarks.create({
url: "http://localhost:7647/i2ptunnelmgr",
title: "Hidden Services Manager",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
} else {
var createBookmark = browser.bookmarks.create({
url: "http://localhost:7657/i2ptunnelmgr",
title: "Hidden Services Manager",
parentId: bookmarkToolbar[0].id
});
createBookmark.then(onCreated);
}
console.log("(bookmarks) adding i2ptunnel bookmark");
}
console.log("(bookmarks) checking if we're running in an I2P Browser");
var gettingInfo = browser.proxy.settings.get({});
gettingInfo.then(gotProxyInfo);
}
}
function onRejected(error) {
console.log(`An error: ${error}`);
}
function onCreated(node) {
console.log("Bookmarked", node);
}
var b0 = browser.bookmarks.search({
title: "Home Page"
});
b0.then(bookHome, onRejected);
var b1 = browser.bookmarks.search({
url: "http://localhost:7657/i2psnark",
title: "Bittorrent"
});
b1.then(bookTorrent, onRejected);
var b2 = browser.bookmarks.search({
url: "http://localhost:7657/i2ptunnelmgr",
title: "Hidden Services Manager"
});
b2.then(bookI2PTunnel, onRejected);
var b3 = browser.bookmarks.search({
url: "http://localhost:7657/webmail",
title: "Web Mail"
});
b3.then(bookMail, onRejected);
}
var bt = browser.bookmarks.search({
query: "Toolbar"
});
bt.then(bookmarks);