2019-06-17 19:17:11 -04:00
|
|
|
|
2019-07-10 00:47:30 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
browser.contextualIdentities.query({}).then(onGot, onError);
|
|
|
|
|
|
|
|
|
2019-06-19 10:44:03 -04:00
|
|
|
function getChrome() {
|
2019-06-29 00:49:59 -04:00
|
|
|
if (browser.runtime.getBrowserInfo == undefined) {
|
|
|
|
return true
|
2019-06-19 10:44:03 -04:00
|
|
|
}
|
2019-06-29 00:49:59 -04:00
|
|
|
return false
|
2019-06-19 10:44:03 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 19:17:11 -04:00
|
|
|
function isDroid() {
|
2019-06-27 15:40:43 -04:00
|
|
|
if (!getChrome()) {
|
|
|
|
var gettingInfo = browser.runtime.getPlatformInfo();
|
|
|
|
gettingInfo.then((got) => {
|
|
|
|
if (got.os == "android") {
|
|
|
|
console.log("android detected")
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
console.log("desktop detected")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDroid()) {
|
2019-06-27 15:40:43 -04:00
|
|
|
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-19 14:56:55 -05:00
|
|
|
|
2019-02-05 10:53:26 -05:00
|
|
|
function themeWindow(window) {
|
2019-06-27 15:40:43 -04:00
|
|
|
// Check if the window is in private browsing
|
2019-07-10 00:47:30 -04:00
|
|
|
function logTabs(tabInfo) {
|
|
|
|
console.log(tabInfo)
|
2019-07-10 02:29:38 -04:00
|
|
|
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",
|
|
|
|
}
|
|
|
|
});
|
2019-07-10 00:47:30 -04:00
|
|
|
}
|
2019-07-10 02:29:38 -04:00
|
|
|
}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 00:47:30 -04:00
|
|
|
}
|
2019-07-10 02:29:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function onError(e) {
|
|
|
|
console.error(e);
|
2019-07-10 00:47:30 -04:00
|
|
|
}
|
2019-07-12 02:21:14 -04:00
|
|
|
//if (tabInfo[0].cookieStoreId == "firefox-default")
|
|
|
|
browser.contextualIdentities.get(tabInfo[0].cookieStoreId).then(onGot, onError);
|
2019-07-10 00:47:30 -04:00
|
|
|
}
|
|
|
|
function onError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
2019-06-27 15:40:43 -04:00
|
|
|
}
|
2019-07-10 00:47:30 -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
|
|
|
|
2019-06-27 15:40:43 -04:00
|
|
|
function setTitle(window) {
|
2019-07-10 00:47:30 -04:00
|
|
|
function logTabs(tabInfo) {
|
|
|
|
console.log(tabInfo)
|
2019-07-10 02:29:38 -04:00
|
|
|
function onGot(context) {
|
2019-07-12 02:21:14 -04:00
|
|
|
if (context.name == "i2pbrowser") {
|
2019-07-10 02:29:38 -04:00
|
|
|
console.log("Active in I2P window")
|
|
|
|
|
2019-07-10 00:47:30 -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-07-10 02:29:38 -04:00
|
|
|
}
|
|
|
|
function onError(e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
browser.contextualIdentities.get(tabInfo[0].cookieStoreId).then(onGot, onError);
|
2019-06-27 15:40:43 -04:00
|
|
|
}
|
2019-07-10 00:47:30 -04:00
|
|
|
function onError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
}
|
|
|
|
var querying = browser.tabs.query({
|
|
|
|
currentWindow: true,
|
|
|
|
active: true
|
|
|
|
});
|
|
|
|
querying.then(logTabs, onError);
|
2019-02-19 11:43:44 -05:00
|
|
|
}
|
2019-02-07 20:14:57 -05:00
|
|
|
|
2019-06-27 15:40:43 -04:00
|
|
|
function setTitleError(window) {
|
|
|
|
alert("plugin error setting title on", window.id)
|
2019-02-19 11:43:44 -05:00
|
|
|
}
|
2019-02-07 20:14:57 -05:00
|
|
|
|
2019-03-15 21:45:59 -04:00
|
|
|
chrome.windows.onCreated.addListener(() => {
|
2019-07-10 02:29:38 -04:00
|
|
|
var gettingStoredSettings = chrome.storage.local.get();
|
2019-06-27 15:40:43 -04:00
|
|
|
gettingStoredSettings.then(setupProxy, onError);
|
2019-02-07 20:14:57 -05:00
|
|
|
});
|
2019-02-19 11:43:44 -05:00
|
|
|
|
2019-03-15 21:45:59 -04:00
|
|
|
chrome.tabs.onCreated.addListener(() => {
|
2019-07-10 02:29:38 -04:00
|
|
|
var getting = browser.windows.getCurrent({
|
2019-06-27 15:40:43 -04:00
|
|
|
populate: true
|
|
|
|
});
|
|
|
|
getting.then(setTitle, setTitleError);
|
2019-02-19 11:43:44 -05:00
|
|
|
});
|