Files
I2P_in_Private_Browsing_Mod…/background.js

175 lines
4.3 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-10-06 15:18:10 -04:00
if (ids.indexOf("i2pbrowser") == -1) {
browser.contextualIdentities
.create({
name: "i2pbrowser",
color: "orange",
2019-10-06 15:18:10 -04:00
icon: "fingerprint"
})
.then(onCreated, onError);
}
2019-10-06 22:11:23 -04:00
if (ids.indexOf("routerconsole") == -1) {
browser.contextualIdentities
.create({
name: "routerconsole",
color: "blue",
2019-10-06 22:11:23 -04:00
icon: "briefcase"
})
.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) {
if (context.name == "i2pbrowser") {
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-10-08 19:10:13 -04:00
} else if (context.name == "routerconsole") {
console.log("Active in I2P window");
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-10-06 15:18:10 -04:00
} else {
console.log("Not active in I2P window");
}
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) {
if (context.name == "i2pbrowser") {
console.log("Active in I2P window");
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-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
});