Files
I2P_in_Private_Browsing_Mod…/background.js

164 lines
3.9 KiB
JavaScript
Raw Normal View History

2019-06-17 19:17:11 -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() {
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()) {
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)
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 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 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);
}
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)
2019-07-10 02:29:38 -04:00
function onGot(context) {
if (context.name == "i2pbrowser") {
2019-07-10 02:29:38 -04:00
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-07-10 02:29:38 -04:00
}
function onError(e) {
console.error(e);
}
browser.contextualIdentities.get(tabInfo[0].cookieStoreId).then(onGot, onError);
}
function onError(error) {
console.log(`Error: ${error}`);
}
var querying = browser.tabs.query({
currentWindow: true,
active: true
});
querying.then(logTabs, onError);
}
2019-02-07 20:14:57 -05:00
function setTitleError(window) {
alert("plugin error setting title on", window.id)
}
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();
gettingStoredSettings.then(setupProxy, onError);
2019-02-07 20:14:57 -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({
populate: true
});
getting.then(setTitle, setTitleError);
});