Files
I2P_in_Private_Browsing_Mod…/background.js

332 lines
8.5 KiB
JavaScript
Raw Normal View History

function onGot(contexts) {
2019-10-06 15:18:10 -04:00
var ids = [];
for (let context of contexts) {
console.log(`Name: ${context.name}`);
ids.push(context.name);
}
console.log("Checking new contexts");
2019-11-11 16:34:41 -05:00
if (ids.indexOf("I2P Browsing") == -1) {
2019-10-06 15:18:10 -04:00
browser.contextualIdentities
.create({
2019-11-11 16:34:41 -05:00
name: "I2P Browsing",
color: "orange",
2019-10-06 15:18:10 -04:00
icon: "fingerprint"
})
.then(onCreated, onError);
}
2019-11-11 16:34:41 -05:00
if (ids.indexOf("Web Browsing") == -1) {
browser.contextualIdentities
.create({
2019-11-11 16:34:41 -05:00
name: "Web Browsing",
color: "red",
icon: "circle"
})
.then(onCreated, onError);
}
2019-11-11 16:34:41 -05:00
if (ids.indexOf("Router Console") == -1) {
2019-10-06 22:11:23 -04:00
browser.contextualIdentities
.create({
2019-11-11 16:34:41 -05:00
name: "Router Console",
color: "blue",
2019-10-06 22:11:23 -04:00
icon: "briefcase"
})
.then(onCreated, onError);
}
2019-11-11 16:34:41 -05:00
if (ids.indexOf("Hidden Services Manager") == -1) {
browser.contextualIdentities
.create({
name: "Hidden Services Manager",
color: "green",
icon: "tree"
})
.then(onCreated, onError);
}
if (ids.indexOf("Web Mail") == -1) {
browser.contextualIdentities
.create({
name: "Web Mail",
color: "yellow",
icon: "briefcase"
})
.then(onCreated, onError);
}
if (ids.indexOf("Bittorrent") == -1) {
browser.contextualIdentities
.create({
name: "Bittorrent",
color: "purple",
icon: "chill"
})
.then(onCreated, onError);
}
}
2019-10-28 01:11:16 -04:00
function onCreated(context) {
console.log(`New identity's ID: ${context.cookieStoreId}.`);
}
function onError(e) {
2019-10-06 15:18:10 -04:00
console.error(e);
}
2019-10-06 15:14:53 -04:00
browser.contextualIdentities.query({}).then(onGot, onError);
2019-06-17 19:17:11 -04:00
if (!isDroid()) {
2019-10-06 15:18:10 -04:00
chrome.windows.onCreated.addListener(themeWindow);
2019-10-28 01:11:16 -04:00
chrome.windows.onFocusChanged.addListener(themeWindow);
chrome.windows.onRemoved.addListener(themeWindow);
2019-10-07 22:51:53 -04:00
chrome.tabs.onUpdated.addListener(themeWindowByTab);
chrome.tabs.onActivated.addListener(themeWindowByTab);
2019-06-17 19:17:11 -04:00
}
2019-02-05 10:53:26 -05:00
2019-03-15 21:45:59 -04:00
var titlepref = chrome.i18n.getMessage("titlePreface");
var titleprefpriv = chrome.i18n.getMessage("titlePrefacePrivate");
2019-10-28 01:11:16 -04:00
function themeWindowByTab(tabId) {
function tabWindow(tab) {
getwindow = browser.windows.get(tab.windowId);
getwindow.then(themeWindow);
}
if (typeof tabId === "number") {
tab = browser.tabs.get(tabId);
tab.then(tabWindow);
} else {
tabWindow(tabId);
}
2019-10-07 22:51:53 -04:00
}
2019-02-05 10:53:26 -05:00
function themeWindow(window) {
2019-10-06 15:18:10 -04:00
// Check if the window is in private browsing
function logTabs(tabInfo) {
function onGot(context) {
2019-11-11 16:34:41 -05:00
if (context.name == "I2P Browsing") {
2019-10-06 15:18:10 -04:00
console.log("Active in I2P window");
if (window.incognito) {
chrome.theme.update(window.id, {
colors: {
frame: "#FFC56D",
toolbar: "#FFC56D"
2019-10-06 15:18:10 -04:00
}
});
} else {
chrome.theme.update(window.id, {
colors: {
frame: "#FFC56D",
toolbar: "#FFC56D"
}
2019-10-06 15:18:10 -04:00
});
2019-07-10 02:29:38 -04:00
}
2019-11-11 16:34:41 -05:00
} else if (context.name == "Router Console") {
console.log("Active in Router Console window");
2019-10-08 19:10:13 -04:00
if (window.incognito) {
chrome.theme.update(window.id, {
colors: {
frame: "#A4C8E1",
toolbar: "#A4C8E1"
2019-10-08 19:10:13 -04:00
}
});
} else {
chrome.theme.update(window.id, {
colors: {
frame: "#A4C8E1",
toolbar: "#A4C8E1"
2019-10-08 19:10:13 -04:00
}
});
}
2019-11-11 16:34:41 -05:00
} else if (context.name == "Hidden Services Manager") {
console.log("Active in Hidden Services Manager window");
if (window.incognito) {
chrome.theme.update(window.id, {
colors: {
frame: "#D9D9D6",
toolbar: "#D9D9D6"
}
});
} else {
chrome.theme.update(window.id, {
colors: {
frame: "#D9D9D6",
toolbar: "#D9D9D6"
}
});
}
} else if (context.name == "Web Mail") {
console.log("Active in Web Mail window");
if (window.incognito) {
chrome.theme.update(window.id, {
colors: {
frame: "#F7E59A",
toolbar: "#F7E59A"
}
});
} else {
chrome.theme.update(window.id, {
colors: {
frame: "#F7E59A",
toolbar: "#F7E59A"
}
});
}
} else if (context.name == "Bittorrent") {
console.log("Active in Bittorrent window");
if (window.incognito) {
chrome.theme.update(window.id, {
colors: {
frame: "#A48FE1",
toolbar: "#A48FE1"
}
});
} else {
chrome.theme.update(window.id, {
colors: {
frame: "#A48FE1",
toolbar: "#A48FE1"
}
});
}
2019-10-06 15:18:10 -04:00
} else {
console.log("Not active in I2P window");
chrome.theme.reset(window.id);
2019-10-06 15:18:10 -04:00
}
2019-07-10 02:29:38 -04:00
}
if (
tabInfo[0].cookieStoreId != "firefox-default" &&
tabInfo[0].cookieStoreId != "firefox-private"
) {
2019-10-07 22:51:53 -04:00
browser.contextualIdentities
2019-10-08 19:10:13 -04:00
.get(tabInfo[0].cookieStoreId)
.then(onGot, onError);
} else {
chrome.theme.reset(window.id);
2019-10-07 22:51:53 -04:00
}
2019-10-06 15:18:10 -04:00
}
var querying = browser.tabs.query({
currentWindow: true,
active: true
});
querying.then(logTabs, onError);
2019-02-05 10:53:26 -05:00
}
2019-02-07 20:14:57 -05:00
function setTitle(window) {
2019-10-06 15:18:10 -04:00
function logTabs(tabInfo) {
console.log(tabInfo);
function onGot(context) {
2019-11-11 16:34:41 -05:00
if (context.name == "I2P Browsing") {
console.log("Active in I2P window");
if (window.incognito) {
chrome.windows.update(window.id, {
titlePreface: titleprefpriv
});
} else {
chrome.windows.update(window.id, {
titlePreface: titlepref
});
}
} else if (context.name == "Web Browsing") {
console.log("Active in Web window");
if (window.incognito) {
chrome.windows.update(window.id, {
titlePreface: titleprefpriv
});
} else {
chrome.windows.update(window.id, {
titlePreface: titlepref
});
}
} else if (context.name == "Router Console") {
console.log("Active in Router Console window");
if (window.incognito) {
chrome.windows.update(window.id, {
titlePreface: titleprefpriv
});
} else {
chrome.windows.update(window.id, {
titlePreface: titlepref
});
}
} else if (context.name == "Hidden Services Manager") {
console.log("Active in Hidden Services Manager window");
if (window.incognito) {
chrome.windows.update(window.id, {
titlePreface: titleprefpriv
});
} else {
chrome.windows.update(window.id, {
titlePreface: titlepref
});
}
} else if (context.name == "Web Mail") {
console.log("Active in Web Mail window");
if (window.incognito) {
chrome.windows.update(window.id, {
titlePreface: titleprefpriv
});
} else {
chrome.windows.update(window.id, {
titlePreface: titlepref
});
}
} else if (context.name == "Bittorrent") {
2019-10-06 15:18:10 -04:00
console.log("Active in I2P window");
if (window.incognito) {
chrome.windows.update(window.id, {
titlePreface: titleprefpriv
});
} else {
chrome.windows.update(window.id, {
titlePreface: titlepref
});
}
2019-10-06 15:18:10 -04:00
}
2019-07-10 02:29:38 -04:00
}
if (
tabInfo[0].cookieStoreId != "firefox-default" &&
tabInfo[0].cookieStoreId != "firefox-private"
) {
2019-10-06 15:18:10 -04:00
browser.contextualIdentities
.get(tabInfo[0].cookieStoreId)
.then(onGot, onError);
2019-11-11 01:48:37 -05:00
} else {
if (window.incognito) {
chrome.windows.update(window.id, {
titlePreface: ""
});
} else {
chrome.windows.update(window.id, {
titlePreface: ""
});
}
}
2019-10-06 15:18:10 -04:00
}
var querying = browser.tabs.query({
currentWindow: true,
active: true
});
querying.then(logTabs, onError);
}
2019-02-07 20:14:57 -05:00
2019-03-15 21:45:59 -04:00
chrome.windows.onCreated.addListener(() => {
/* var gettingStoredSettings = chrome.storage.local.get();
gettingStoredSettings.then(setupProxy, onError); */
2019-10-06 15:18:10 -04:00
chrome.storage.local.get(function(got) {
setupProxy();
});
2019-02-07 20:14:57 -05:00
});
2019-03-15 21:45:59 -04:00
chrome.tabs.onCreated.addListener(() => {
2019-10-06 15:18:10 -04:00
var getting = browser.windows.getCurrent({
populate: true
});
getting.then(setTitle, onError);
2019-10-06 15:14:53 -04:00
});