add a mode for semi-safe localhost browsing
This commit is contained in:
1
Makefile
1
Makefile
@@ -176,7 +176,6 @@ upload-deb:
|
||||
fmt:
|
||||
cleancss -O1 all -O2 all --format beautify home.css -o .home.css && mv .home.css home.css
|
||||
cleancss -O1 all -O2 all --format beautify info.css -o .info.css && mv .info.css info.css
|
||||
#find . -path ./node_modules -prune -o -name '*.css' -exec cleancss -O1 --format beautify {} \;
|
||||
find . -path ./node_modules -prune -o -name '*.js*' -exec prettier --write {} \;
|
||||
|
||||
lint:
|
||||
|
||||
@@ -23,6 +23,14 @@
|
||||
"message": "Web Browser (Private)",
|
||||
"description": "Preface for the browser titlebar"
|
||||
},
|
||||
"localPreface": {
|
||||
"message": "Localhost Browser",
|
||||
"description": "Preface for the browser titlebar"
|
||||
},
|
||||
"localPrefacePrivate": {
|
||||
"message": "Localhost Browser (Private)",
|
||||
"description": "Preface for the browser titlebar"
|
||||
},
|
||||
"routerPreface": {
|
||||
"message": "Router Console",
|
||||
"description": "Preface for the browser titlebar"
|
||||
|
||||
@@ -10,6 +10,7 @@ var torrentpref = chrome.i18n.getMessage("torrentPreface");
|
||||
var torrentprefpriv = chrome.i18n.getMessage("torrentPrefacePrivate");
|
||||
var tunnelpref = chrome.i18n.getMessage("i2ptunnelPreface");
|
||||
var tunnelprefpriv = chrome.i18n.getMessage("i2ptunnelPrefacePrivate");
|
||||
var localpref = chrome.i18n.getMessage("localPreface");
|
||||
|
||||
function onContextsGot(contexts) {
|
||||
var ids = [];
|
||||
@@ -72,6 +73,15 @@ function onContextsGot(contexts) {
|
||||
})
|
||||
.then(onCreated, onError);
|
||||
}
|
||||
if (ids.indexOf(localpref) == -1) {
|
||||
browser.contextualIdentities
|
||||
.create({
|
||||
name: localpref,
|
||||
color: "red",
|
||||
icon: "fence"
|
||||
})
|
||||
.then(onCreated, onError);
|
||||
}
|
||||
}
|
||||
|
||||
function onCreated(context) {
|
||||
@@ -113,8 +123,33 @@ function themeWindowByTab(tabId) {
|
||||
}
|
||||
}
|
||||
|
||||
function isEmpty(obj) {
|
||||
if (obj == undefined || obj == null) return true;
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var oldtheme;
|
||||
|
||||
var getOldTheme = async function getOldTheme() {
|
||||
foundtheme = await browser.theme.getCurrent();
|
||||
if (!isEmpty(foundtheme)) {
|
||||
oldtheme = foundtheme;
|
||||
console.log("Found old theme", oldtheme);
|
||||
}
|
||||
return oldtheme;
|
||||
};
|
||||
|
||||
getOldTheme();
|
||||
|
||||
function themeWindow(window) {
|
||||
// Check if the window is in private browsing
|
||||
function onThemeError() {
|
||||
console.log("got theme", oldtheme);
|
||||
browser.theme.update(oldtheme);
|
||||
}
|
||||
function logTabs(tabInfo) {
|
||||
function onContextGotTheme(context) {
|
||||
if (context.name == titlepref) {
|
||||
@@ -204,7 +239,8 @@ function themeWindow(window) {
|
||||
}
|
||||
} else {
|
||||
console.log("Not active in I2P window");
|
||||
browser.theme.reset(window.id);
|
||||
if (!isEmpty(oldtheme)) browser.theme.update(window.id, oldtheme);
|
||||
else browser.theme.reset();
|
||||
}
|
||||
}
|
||||
if (
|
||||
@@ -213,9 +249,10 @@ function themeWindow(window) {
|
||||
) {
|
||||
browser.contextualIdentities
|
||||
.get(tabInfo[0].cookieStoreId)
|
||||
.then(onContextGotTheme, onError);
|
||||
.then(onContextGotTheme, onThemeError);
|
||||
} else {
|
||||
browser.theme.reset(window.id);
|
||||
if (!isEmpty(oldtheme)) browser.theme.update(window.id, oldtheme);
|
||||
else browser.theme.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,8 +265,6 @@ function themeWindow(window) {
|
||||
|
||||
function setTitle(window) {
|
||||
function logTabs(tabInfo) {
|
||||
console.log(tabInfo);
|
||||
|
||||
function onContextGotTitle(context) {
|
||||
if (context.name == titlepref) {
|
||||
console.log("Active in I2P window");
|
||||
@@ -370,7 +405,7 @@ gettingInfo.then(got => {
|
||||
});
|
||||
|
||||
function handleUpdated(updateInfo) {
|
||||
if (updateInfo.theme.colors) {
|
||||
if (updateInfo.theme) {
|
||||
console.log(`Theme was applied: ${updateInfo.theme}`);
|
||||
} else {
|
||||
console.log("Theme was removed");
|
||||
|
||||
6
proxy.js
6
proxy.js
@@ -103,14 +103,14 @@ var handleContextProxyRequest = async function(requestDetails) {
|
||||
if (!routerHost(requestDetails.url)) {
|
||||
if (localHost(requestDetails.url)) {
|
||||
console.log(
|
||||
"(proxy) non-routerconsole localhost url, dropping",
|
||||
"(proxy) non-routerconsole localhost url, will not interfere",
|
||||
requestDetails.url
|
||||
);
|
||||
proxy = {
|
||||
/*proxy = {
|
||||
type: "http",
|
||||
host: "localhost",
|
||||
port: "65535"
|
||||
};
|
||||
};*/
|
||||
}
|
||||
} else if (i2pHost(requestDetails.url)) {
|
||||
proxy = {
|
||||
|
||||
36
scrub.js
36
scrub.js
@@ -237,6 +237,34 @@ var contextSetup = async function(requestDetails) {
|
||||
console.log("(isolate)Context Error", error);
|
||||
}
|
||||
};
|
||||
var localTabFind = async function(tabId) {
|
||||
try {
|
||||
var context = await browser.contextualIdentities.query({
|
||||
name: localpref
|
||||
});
|
||||
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
||||
function Create(window) {
|
||||
function onCreated(tab) {
|
||||
if (tabId != undefined) {
|
||||
console.log("(isolate) Closing old, un-isolated tab");
|
||||
browser.tabs.remove(tabId.id);
|
||||
}
|
||||
}
|
||||
var created = browser.tabs.create({
|
||||
active: true,
|
||||
cookieStoreId: context[0].cookieStoreId,
|
||||
url: requestDetails.url
|
||||
});
|
||||
created.then(onCreated, onError);
|
||||
}
|
||||
var getting = browser.tabs.getCurrent();
|
||||
getting.then(Create, onError);
|
||||
return tabId;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("(isolate)Context Error", error);
|
||||
}
|
||||
};
|
||||
var anyTabFind = async function(tabId) {
|
||||
try {
|
||||
var context = await browser.contextualIdentities.query({
|
||||
@@ -310,7 +338,13 @@ var contextSetup = async function(requestDetails) {
|
||||
var mtab = tab.then(i2pTabFind, onError);
|
||||
return requestDetails;
|
||||
}
|
||||
let localhost = localHost(requestDetails.url);
|
||||
let routerhost = routerHost(requestDetails.url);
|
||||
if (localhost && !routerhost) {
|
||||
var tab = tabGet(requestDetails.tabId);
|
||||
var mtab = tab.then(localTabFind, onError);
|
||||
return requestDetails;
|
||||
}
|
||||
if (routerhost) {
|
||||
if (routerhost === "i2ptunnelmgr") {
|
||||
var tab = tabGet(requestDetails.tabId);
|
||||
@@ -331,7 +365,7 @@ var contextSetup = async function(requestDetails) {
|
||||
}
|
||||
} else {
|
||||
var tab = tabGet(requestDetails.tabId);
|
||||
var mtab = tab.then(anyTabFind, onError);
|
||||
var mtab = tab.then(routerTabFind, onError);
|
||||
return requestDetails;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user