Files
I2P_in_Private_Browsing_Mod…/background.js

148 lines
4.2 KiB
JavaScript
Raw Normal View History

function onGot(contexts) {
var ids = []
for (let context of contexts) {
console.log(`Name: ${context.name}`);
ids.push(context.name)
}
if (ids.indexOf("i2pbrowser") == -1) {
function onCreated(context) {
console.log(`New identity's ID: ${context.cookieStoreId}.`);
}
function onError(e) {
console.error(e);
}
browser.contextualIdentities.create({
name: "i2pbrowser",
color: "purple",
icon: "fingerprint"
}).then(onCreated, onError);
}
}
function onError(e) {
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()) {
chrome.windows.onCreated.addListener(themeWindow);
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-02-05 10:53:26 -05:00
function themeWindow(window) {
// Check if the window is in private browsing
function logTabs(tabInfo) {
console.log(tabInfo)
function onGot(context) {
if (context.name == "i2pbrowser") {
console.log("Active in I2P window")
if (window.incognito) {
chrome.theme.update(window.id, {
colors: {
frame: "#2D4470",
toolbar: "#2D4470",
}
});
} else {
chrome.theme.update(window.id, {
colors: {
frame: "#9DABD5",
toolbar: "#9DABD5",
}
});
}
} else {
console.log("Not active in I2P window")
if (window.incognito) {
chrome.theme.update(window.id, {
colors: {
frame: undefined,
toolbar: undefined,
}
});
} else {
chrome.theme.update(window.id, {
colors: {
frame: undefined,
toolbar: undefined,
}
});
}
}
2019-07-10 02:29:38 -04:00
}
function onError(e) {
console.error(e);
}
if (tabInfo[0].cookieStoreId != "firefox-default")
browser.contextualIdentities.get(tabInfo[0].cookieStoreId).then(onGot, onError);
2019-07-10 02:29:38 -04:00
}
function onError(error) {
console.log(`Error: ${error}`);
}
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) {
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
});
}
}
}
function onError(e) {
console.error(e);
}
if (tabInfo[0].cookieStoreId != "firefox-default")
browser.contextualIdentities.get(tabInfo[0].cookieStoreId).then(onGot, onError);
2019-07-10 02:29:38 -04:00
}
function onError(error) {
console.log(`Error: ${error}`);
2019-07-10 02:29:38 -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);
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(() => {
var getting = browser.windows.getCurrent({
populate: true
});
2019-10-06 15:14:53 -04:00
getting.then(setTitle, onError);
});