Files
I2P_in_Private_Browsing_Mod…/background.js

393 lines
10 KiB
JavaScript
Raw Normal View History

var titlepref = chrome.i18n.getMessage("titlePreface");
var titleprefpriv = chrome.i18n.getMessage("titlePrefacePrivate");
var webpref = chrome.i18n.getMessage("webPreface");
var webprefpriv = chrome.i18n.getMessage("webPrefacePrivate");
var routerpref = chrome.i18n.getMessage("routerPreface");
var routerprefpriv = chrome.i18n.getMessage("routerPrefacePrivate");
var mailpref = chrome.i18n.getMessage("mailPreface");
var mailprefpriv = chrome.i18n.getMessage("mailPrefacePrivate");
var torrentpref = chrome.i18n.getMessage("torrentPreface");
var torrentprefpriv = chrome.i18n.getMessage("torrentPrefacePrivate");
var tunnelpref = chrome.i18n.getMessage("i2ptunnelPreface");
var tunnelprefpriv = chrome.i18n.getMessage("i2ptunnelPrefacePrivate");
2019-11-24 17:14:43 -05:00
function onContextsGot(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");
if (ids.indexOf(titlepref) == -1) {
2019-10-06 15:18:10 -04:00
browser.contextualIdentities
.create({
name: titlepref,
color: "orange",
2019-10-06 15:18:10 -04:00
icon: "fingerprint"
})
.then(onCreated, onError);
}
if (ids.indexOf(webpref) == -1) {
browser.contextualIdentities
.create({
name: webpref,
2019-11-11 16:34:41 -05:00
color: "red",
icon: "circle"
})
.then(onCreated, onError);
}
if (ids.indexOf(routerpref) == -1) {
2019-10-06 22:11:23 -04:00
browser.contextualIdentities
.create({
name: routerpref,
color: "blue",
2019-10-06 22:11:23 -04:00
icon: "briefcase"
})
.then(onCreated, onError);
}
if (ids.indexOf(tunnelpref) == -1) {
2019-11-11 16:34:41 -05:00
browser.contextualIdentities
.create({
name: tunnelpref,
2019-11-11 16:34:41 -05:00
color: "green",
icon: "tree"
})
.then(onCreated, onError);
}
if (ids.indexOf(mailpref) == -1) {
2019-11-11 16:34:41 -05:00
browser.contextualIdentities
.create({
name: mailpref,
2019-11-11 16:34:41 -05:00
color: "yellow",
icon: "briefcase"
})
.then(onCreated, onError);
}
if (ids.indexOf(torrentpref) == -1) {
2019-11-11 16:34:41 -05:00
browser.contextualIdentities
.create({
name: torrentpref,
2019-11-11 16:34:41 -05:00
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}.`);
}
2019-11-24 17:14:43 -05:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os == "android") {
2019-11-24 20:57:41 -05:00
browser.contextualIdentities.query({}).then(onContextsGot, onError);
2019-11-24 17:14:43 -05:00
} else {
browser.windows.onCreated.addListener(() => {
browser.contextualIdentities.query({}).then(onContextsGot, onError);
});
}
});
2019-06-17 19:17:11 -04:00
2019-11-24 04:13:12 -05:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os == "android") {
} else {
browser.windows.onCreated.addListener(themeWindow);
browser.windows.onFocusChanged.addListener(themeWindow);
browser.windows.onRemoved.addListener(themeWindow);
browser.tabs.onUpdated.addListener(themeWindowByTab);
browser.tabs.onActivated.addListener(themeWindowByTab);
}
});
2019-02-05 10:53:26 -05:00
2019-10-28 01:11:16 -04:00
function themeWindowByTab(tabId) {
function tabWindow(tab) {
2019-11-24 04:13:12 -05:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os == "android") {
getwindow = browser.tabs.get(tab.tabId);
getwindow.then(themeWindow);
} else {
getwindow = browser.windows.get(tab.windowId);
getwindow.then(themeWindow);
}
});
2019-10-28 01:11:16 -04:00
}
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) {
2019-11-24 17:14:43 -05:00
function onContextGotTheme(context) {
if (context.name == titlepref) {
2019-10-06 15:18:10 -04:00
console.log("Active in I2P window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-10-06 15:18:10 -04:00
colors: {
frame: "#FFC56D",
toolbar: "#FFC56D"
2019-10-06 15:18:10 -04:00
}
});
} else {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-10-06 15:18:10 -04:00
colors: {
frame: "#FFC56D",
toolbar: "#FFC56D"
}
2019-10-06 15:18:10 -04:00
});
2019-07-10 02:29:38 -04:00
}
} else if (context.name == routerpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Router Console window");
2019-10-08 19:10:13 -04:00
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-10-08 19:10:13 -04:00
colors: {
frame: "#A4C8E1",
toolbar: "#A4C8E1"
2019-10-08 19:10:13 -04:00
}
});
} else {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-10-08 19:10:13 -04:00
colors: {
frame: "#A4C8E1",
toolbar: "#A4C8E1"
2019-10-08 19:10:13 -04:00
}
});
}
} else if (context.name == tunnelpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Hidden Services Manager window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-11-11 16:34:41 -05:00
colors: {
frame: "#D9D9D6",
toolbar: "#D9D9D6"
}
});
} else {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-11-11 16:34:41 -05:00
colors: {
frame: "#D9D9D6",
toolbar: "#D9D9D6"
}
});
}
} else if (context.name == mailpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Web Mail window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-11-11 16:34:41 -05:00
colors: {
frame: "#F7E59A",
toolbar: "#F7E59A"
}
});
} else {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-11-11 16:34:41 -05:00
colors: {
frame: "#F7E59A",
toolbar: "#F7E59A"
}
});
}
} else if (context.name == torrentpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Bittorrent window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-11-11 16:34:41 -05:00
colors: {
frame: "#A48FE1",
toolbar: "#A48FE1"
}
});
} else {
2019-11-24 04:13:12 -05:00
browser.theme.update(window.id, {
2019-11-11 16:34:41 -05:00
colors: {
frame: "#A48FE1",
toolbar: "#A48FE1"
}
});
}
2019-10-06 15:18:10 -04:00
} else {
console.log("Not active in I2P window");
2019-11-24 04:13:12 -05:00
browser.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)
2019-11-24 17:14:43 -05:00
.then(onContextGotTheme, onError);
2019-10-08 19:10:13 -04:00
} else {
2019-11-24 04:13:12 -05:00
browser.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);
2019-11-24 17:14:43 -05:00
function onContextGotTitle(context) {
if (context.name == titlepref) {
2019-11-11 16:34:41 -05:00
console.log("Active in I2P window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
2019-11-11 16:34:41 -05:00
titlePreface: titleprefpriv
});
} else {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
2019-11-11 16:34:41 -05:00
titlePreface: titlepref
});
}
} else if (context.name == webpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Web window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: ""
2019-11-11 16:34:41 -05:00
});
} else {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: ""
2019-11-11 16:34:41 -05:00
});
}
} else if (context.name == routerpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Router Console window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: routerprefpriv
2019-11-11 16:34:41 -05:00
});
} else {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: routerpref
2019-11-11 16:34:41 -05:00
});
}
} else if (context.name == tunnelpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Hidden Services Manager window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: tunnelprefpriv
2019-11-11 16:34:41 -05:00
});
} else {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: tunnelpref
2019-11-11 16:34:41 -05:00
});
}
} else if (context.name == mailpref) {
2019-11-11 16:34:41 -05:00
console.log("Active in Web Mail window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: mailprefpriv
2019-11-11 16:34:41 -05:00
});
} else {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: mailpref
2019-11-11 16:34:41 -05:00
});
}
} else if (context.name == torrentpref) {
2019-10-06 15:18:10 -04:00
console.log("Active in I2P window");
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: torrentprefpriv
2019-10-06 15:18:10 -04:00
});
} else {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
titlePreface: torrentpref
2019-10-06 15:18:10 -04:00
});
}
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)
2019-11-24 17:14:43 -05:00
.then(onContextGotTitle, onError);
2019-11-11 01:48:37 -05:00
} else {
if (window.incognito) {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
2019-11-11 01:48:37 -05:00
titlePreface: ""
});
} else {
2019-11-24 04:13:12 -05:00
browser.windows.update(window.id, {
2019-11-11 01:48:37 -05:00
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-11-24 04:32:35 -05:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os == "android") {
} else {
browser.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-11-24 04:13:12 -05:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os == "android") {
} else {
browser.tabs.onCreated.addListener(() => {
var getting = browser.windows.getCurrent({
populate: true
});
getting.then(setTitle, onError);
});
}
2019-10-06 15:14:53 -04:00
});
2019-11-24 04:13:12 -05:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os == "android") {
} else {
browser.tabs.onActivated.addListener(() => {
var getting = browser.windows.getCurrent({
populate: true
});
getting.then(setTitle, onError);
});
}
2019-11-12 00:11:52 -05:00
});
function handleUpdated(updateInfo) {
if (updateInfo.theme.colors) {
console.log(`Theme was applied: ${updateInfo.theme}`);
} else {
console.log(`Theme was removed`);
}
}
browser.theme.onUpdated.addListener(handleUpdated);