2023-05-25 03:49:17 +00:00
|
|
|
/* eslint-disable max-len */
|
2022-10-24 19:57:51 -04:00
|
|
|
var titlepref = chrome.i18n.getMessage("titlePreface");
|
|
|
|
var webpref = chrome.i18n.getMessage("webPreface");
|
|
|
|
var routerpref = chrome.i18n.getMessage("routerPreface");
|
|
|
|
var mailpref = chrome.i18n.getMessage("mailPreface");
|
|
|
|
var torrentpref = chrome.i18n.getMessage("torrentPreface");
|
|
|
|
var tunnelpref = chrome.i18n.getMessage("i2ptunnelPreface");
|
|
|
|
var ircpref = chrome.i18n.getMessage("ircPreface");
|
|
|
|
var extensionpref = chrome.i18n.getMessage("extensionPreface");
|
|
|
|
var muwirepref = chrome.i18n.getMessage("muwirePreface");
|
|
|
|
var botepref = chrome.i18n.getMessage("botePreface");
|
|
|
|
var blogpref = chrome.i18n.getMessage("blogPreface");
|
|
|
|
var blogprefpriv = chrome.i18n.getMessage("blogPrefacePrivate");
|
|
|
|
var torpref = chrome.i18n.getMessage("torPreface");
|
|
|
|
var torprefpriv = chrome.i18n.getMessage("torPrefacePrivate");
|
2019-11-11 23:31:37 -05:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function contextScrub(requestDetails) {
|
|
|
|
function handleHeaderError() {
|
|
|
|
// log error message
|
|
|
|
console.log("Error: Header could not be scrubbed");
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
function headerScrub() {
|
|
|
|
const titlePrefix = "myob";
|
|
|
|
const userAgent = "MYOB/6.66 (AN/ON)";
|
|
|
|
if (requestDetails && requestDetails.name === titlePrefix) {
|
|
|
|
for (const header of requestDetails.requestHeaders) {
|
|
|
|
if (header.name.toLowerCase() === "user-agent") {
|
|
|
|
header.value = userAgent;
|
2022-10-08 17:21:55 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
return { requestHeaders: requestDetails.requestHeaders };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async function getContext(tabInfo) {
|
|
|
|
try {
|
|
|
|
const context = await browser.contextualIdentities.get(
|
|
|
|
tabInfo.cookieStoreId
|
|
|
|
);
|
|
|
|
return context;
|
|
|
|
} catch (error) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
2022-10-16 16:08:01 -04:00
|
|
|
if (requestDetails.tabId > 0) {
|
2023-05-25 03:49:17 +00:00
|
|
|
let tab = getTab(requestDetails.tabId);
|
|
|
|
let context = tab.then(getContext, handleHeaderError);
|
|
|
|
let req = context.then(headerScrub, handleHeaderError);
|
2022-10-16 16:08:01 -04:00
|
|
|
return req;
|
2019-10-06 13:58:26 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
} catch (error) {
|
2022-10-24 19:57:51 -04:00
|
|
|
console.log("(scrub)Not scrubbing non-I2P request.", error);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
2019-10-07 20:52:03 -04:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
async function getTab(tabId) {
|
|
|
|
try {
|
|
|
|
let tabInfo = await browser.tabs.get(tabId);
|
|
|
|
return tabInfo;
|
|
|
|
} catch (error) {
|
|
|
|
return undefined;
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
2020-03-02 17:34:39 -05:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function i2pTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery browser", tabId);
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, titlepref, false);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
|
|
|
function routerTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery console");
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, routerpref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function i2ptunnelTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery browser");
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, tunnelpref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function snarkTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery torrents");
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
|
|
|
name: torrentpref
|
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
|
|
|
var exemptContext = await browser.contextualIdentities.query({
|
|
|
|
name: titlepref
|
2022-10-16 16:08:01 -04:00
|
|
|
});
|
2023-05-25 03:49:17 +00:00
|
|
|
let tmp = new URL(tabId.url);
|
|
|
|
console.log("(isolate)tabid host", tmp.host);
|
|
|
|
if (!requestDetails.url.includes("snark/" + tmp.host)) {
|
|
|
|
// if (tabId.cookieStoreId != exemptContext[0].cookieStoreId){
|
2022-10-16 16:08:01 -04:00
|
|
|
function Create() {
|
|
|
|
function onCreated(tab) {
|
|
|
|
function closeOldTab(tabs) {
|
|
|
|
if (tabId.id != tab.id) {
|
|
|
|
console.log(
|
2022-10-24 19:57:51 -04:00
|
|
|
"(isolate) Closing un-isolated tab",
|
2022-10-16 16:08:01 -04:00
|
|
|
tabId.id,
|
2022-10-24 19:57:51 -04:00
|
|
|
"in favor of",
|
2022-10-16 16:08:01 -04:00
|
|
|
tab.id,
|
2022-10-24 19:57:51 -04:00
|
|
|
"with context",
|
2022-10-16 16:08:01 -04:00
|
|
|
tab.cookieStoreId
|
|
|
|
);
|
|
|
|
browser.tabs.remove(tabId.id);
|
2023-05-25 03:49:17 +00:00
|
|
|
browser.tabs.move(tab.id, { index: 0 });
|
|
|
|
}
|
|
|
|
for (let index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1) {
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
2021-10-01 12:15:28 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2021-05-28 14:20:57 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
var pins = browser.tabs.query({
|
2023-05-25 03:49:17 +00:00
|
|
|
cookieStoreId: context[0].cookieStoreId
|
2022-10-16 16:08:01 -04:00
|
|
|
});
|
2023-05-25 03:49:17 +00:00
|
|
|
pins.then(closeOldTab, onScrubError);
|
|
|
|
}
|
|
|
|
if (requestDetails.url.endsWith("xhr1.html")) {
|
|
|
|
let hostname = url.split("/")[2];
|
|
|
|
let prefix = url.substr(0, url.indexOf("://") + 3);
|
|
|
|
requestDetails.url = prefix + hostname + "/i2psnark/";
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
2023-05-25 03:49:17 +00:00
|
|
|
pinned: true,
|
2022-10-16 16:08:01 -04:00
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
2023-05-25 03:49:17 +00:00
|
|
|
url: requestDetails.url
|
2022-10-16 16:08:01 -04:00
|
|
|
});
|
|
|
|
created.then(onCreated, onContextError);
|
2021-05-28 14:20:57 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
|
|
|
gettab.then(Create, onContextError);
|
|
|
|
return tabId;
|
|
|
|
}
|
2021-05-28 14:20:57 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.log("(isolate)Context Error", error);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
|
|
|
function muwireTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery muwire");
|
2022-10-16 16:08:01 -04:00
|
|
|
try {
|
2023-05-25 03:49:17 +00:00
|
|
|
return forceIntoIsolation(tabId, muwirepref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function i2pboteTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery bote");
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, botepref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function mailTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery mail");
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, mailpref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function ircTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery irc");
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, ircpref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function torTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery tor");
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, torpref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function blogTabFind(tabId) {
|
|
|
|
console.info("(isolate)Context Discovery blog");
|
|
|
|
try {
|
|
|
|
return forceIntoIsolation(tabId, blogpref, true);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function forceIntoIsolation(tabId, contextidentifier, pin = true) {
|
|
|
|
console.info("(isolate) forcing context for", tabId, contextidentifier, pin);
|
|
|
|
try {
|
|
|
|
var context = await browser.contextualIdentities.query({
|
|
|
|
name: contextidentifier
|
|
|
|
});
|
|
|
|
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
|
|
|
function Create(beforeTab) {
|
|
|
|
console.info("(isolate) isolating before tab:", beforeTab);
|
|
|
|
function onCreated(afterTab) {
|
|
|
|
console.info("(isolate) created isolated tab:", afterTab);
|
|
|
|
function closeOldTab(tabs) {
|
|
|
|
console.info("(isolate) cleaning up tab:", beforeTab);
|
|
|
|
console.info(
|
|
|
|
"(isolate) Closing un-isolated tab",
|
|
|
|
tabId.id,
|
|
|
|
"in favor of",
|
|
|
|
beforeTab.id,
|
|
|
|
"with context",
|
|
|
|
beforeTab.cookieStoreId
|
|
|
|
);
|
|
|
|
browser.tabs.remove(tabId.id);
|
|
|
|
if (pin) {
|
|
|
|
browser.tabs.move(beforeTab.id, { index: 0 });
|
|
|
|
for (let index = 0; index < tabs.length; index++) {
|
|
|
|
if (index != tabs.length - 1) {
|
|
|
|
browser.tabs.remove(tabs[index].id);
|
2020-03-17 04:42:24 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tabId.id,
|
|
|
|
popup: "security.html"
|
|
|
|
});
|
|
|
|
browser.pageAction.show(tabId.id);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
var pins = browser.tabs.query({
|
|
|
|
cookieStoreId: context[0].cookieStoreId
|
|
|
|
});
|
|
|
|
pins.then(closeOldTab, onScrubError);
|
|
|
|
return afterTab;
|
2022-10-07 19:32:52 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
var created = browser.tabs.create({
|
|
|
|
active: true,
|
|
|
|
cookieStoreId: context[0].cookieStoreId,
|
|
|
|
url: beforeTab.url,
|
|
|
|
pinned: pin
|
2022-10-16 16:08:01 -04:00
|
|
|
});
|
2023-05-25 03:49:17 +00:00
|
|
|
return created.then(onCreated, onContextError);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
var gettab = browser.tabs.get(tabId.id);
|
|
|
|
var tab = gettab.then(Create, onContextError);
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error("(isolate)Context Error", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function findOtherContexts() {
|
|
|
|
const prefs = [
|
|
|
|
"titlepref",
|
|
|
|
"routerpref",
|
|
|
|
"mailpref",
|
|
|
|
"torrentpref",
|
|
|
|
"tunnelpref",
|
|
|
|
"ircpref",
|
|
|
|
"muwirepref",
|
|
|
|
"botepref",
|
|
|
|
"blogpref",
|
|
|
|
"torpref"
|
|
|
|
];
|
|
|
|
const contexts = await browser.contextualIdentities.query({});
|
|
|
|
const myContexts = await Promise.all(
|
|
|
|
prefs.map(pref => browser.contextualIdentities.query({ name: pref }))
|
|
|
|
);
|
|
|
|
const otherContexts = contexts.filter(
|
|
|
|
context => !myContexts.some(
|
|
|
|
myContext => myContext[0].cookieStoreId === context.cookieStoreId
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return otherContexts;
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextSetup(requestDetails) {
|
|
|
|
try {
|
|
|
|
async function tabGet(tabId) {
|
2022-10-16 16:08:01 -04:00
|
|
|
try {
|
|
|
|
//console.log("(isolate)Tab ID from Request", tabId);
|
|
|
|
let tabInfo = await browser.tabs.get(tabId);
|
|
|
|
return tabInfo;
|
|
|
|
} catch (error) {
|
2022-10-24 19:57:51 -04:00
|
|
|
console.log("(isolate)Tab error", error);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
if (requestDetails == undefined) {
|
|
|
|
return requestDetails;
|
|
|
|
}
|
2023-06-03 19:43:41 +00:00
|
|
|
if (isProxyHost(requestDetails)) {
|
2023-05-25 03:49:17 +00:00
|
|
|
let setcookie = browser.cookies.set({
|
2022-10-16 16:08:01 -04:00
|
|
|
firstPartyDomain: i2pHostName(requestDetails.url),
|
|
|
|
url: requestDetails.url,
|
2023-05-25 03:49:17 +00:00
|
|
|
secure: true
|
2022-10-16 16:08:01 -04:00
|
|
|
});
|
|
|
|
setcookie.then(onContextGotLog, onContextError);
|
|
|
|
return requestDetails;
|
|
|
|
}
|
2022-10-07 19:32:52 -04:00
|
|
|
|
2022-10-16 16:08:01 -04:00
|
|
|
if (requestDetails.tabId > 0) {
|
|
|
|
var tab = tabGet(requestDetails.tabId);
|
|
|
|
tab.then(isolate);
|
2022-10-08 17:21:55 -04:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function isolate() {
|
|
|
|
const url = requestDetails.url;
|
|
|
|
const localhost = isLocalHost(url);
|
|
|
|
const routerhost = isRouterHost(url);
|
|
|
|
console.info("routerhost:", routerhost);
|
|
|
|
console.info("localhost:", localhost);
|
|
|
|
function tabUpdate(outboundTab) {
|
|
|
|
if (outboundTab) {
|
|
|
|
console.info("updating", outboundTab);
|
|
|
|
browser.tabs.update(outboundTab.id, { url });
|
|
|
|
}
|
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
if (routerhost) {
|
2023-05-25 03:49:17 +00:00
|
|
|
let routertab = {};
|
|
|
|
switch (routerhost) {
|
|
|
|
case "i2ptunnelmgr":
|
|
|
|
routertab = tab.then(i2ptunnelTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
|
|
|
return requestDetails;
|
|
|
|
case "i2psnark":
|
|
|
|
routertab = tab.then(snarkTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
|
|
|
return requestDetails;
|
|
|
|
case "webmail":
|
|
|
|
routertab = tab.then(mailTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
|
|
|
return requestDetails;
|
|
|
|
case "muwire":
|
|
|
|
routertab = tab.then(muwireTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
|
|
|
return requestDetails;
|
|
|
|
case "i2pbote":
|
|
|
|
routertab = tab.then(i2pboteTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
|
|
|
return requestDetails;
|
|
|
|
case "routerconsole":
|
|
|
|
routertab = tab.then(routerTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
|
|
|
return requestDetails;
|
|
|
|
default:
|
|
|
|
return requestDetails;
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
} else if (localhost) {
|
|
|
|
let routertab = {};
|
|
|
|
switch (localhost) {
|
|
|
|
case "blog":
|
|
|
|
routertab = tab.then(blogTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
2022-10-16 16:08:01 -04:00
|
|
|
return requestDetails;
|
2023-05-25 03:49:17 +00:00
|
|
|
case "irc":
|
|
|
|
routertab = tab.then(ircTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
2022-10-16 16:08:01 -04:00
|
|
|
return requestDetails;
|
2023-05-25 03:49:17 +00:00
|
|
|
case "tor":
|
|
|
|
routertab = tab.then(torTabFind, onContextError);
|
|
|
|
routertab.then(tabUpdate);
|
|
|
|
return requestDetails;
|
|
|
|
default:
|
2022-10-16 16:08:01 -04:00
|
|
|
return requestDetails;
|
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
} else if (i2pHost(requestDetails)) {
|
|
|
|
const thn = i2pHostName(url);
|
|
|
|
if (url.includes("=" + thn)) {
|
2022-10-16 16:08:01 -04:00
|
|
|
if (
|
2023-05-25 03:49:17 +00:00
|
|
|
!url.includes("://github.com") ||
|
|
|
|
!url.includes("://notabug.org") ||
|
|
|
|
!url.includes("://i2pgit.org") ||
|
|
|
|
!url.includes("://gitlab.com")
|
2022-10-16 16:08:01 -04:00
|
|
|
) {
|
2023-05-25 03:49:17 +00:00
|
|
|
console.log("(scrub)checking search hostnames =" + thn);
|
|
|
|
const tpt = url.split("=" + thn, 2);
|
|
|
|
requestDetails.url =
|
|
|
|
"http://" + thn + "/" + tpt[1].replace("%2F", "");
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
console.log("(scrub) new hostname", url);
|
|
|
|
const setcookie = browser.cookies.set({
|
|
|
|
firstPartyDomain: i2pHostName(url),
|
|
|
|
url,
|
|
|
|
secure: true
|
2022-10-16 16:08:01 -04:00
|
|
|
});
|
|
|
|
setcookie.then(onContextGotLog, onContextError);
|
2023-05-25 03:49:17 +00:00
|
|
|
const i2ptab = tab.then(i2pTabFind, onContextError);
|
|
|
|
i2ptab.then(tabUpdate);
|
2022-10-16 16:08:01 -04:00
|
|
|
return requestDetails;
|
2023-06-03 19:43:41 +00:00
|
|
|
} else if (isExtensionHost(requestDetails)) {
|
2022-10-16 16:08:01 -04:00
|
|
|
return requestDetails;
|
|
|
|
}
|
|
|
|
}
|
2019-10-07 20:52:03 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
} catch (error) {
|
2022-10-24 19:57:51 -04:00
|
|
|
console.log("(isolate)Not an I2P request, blackholing", error);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
2019-10-06 13:58:26 -04:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function coolheadersSetup(incomingHeaders) {
|
2022-10-16 16:08:01 -04:00
|
|
|
var asyncSetPageAction = new Promise((resolve, reject) => {
|
|
|
|
window.setTimeout(() => {
|
2023-05-25 03:49:17 +00:00
|
|
|
if (incomingHeaders.tabId != undefined) {
|
|
|
|
let popup = browser.pageAction.getPopup({
|
|
|
|
tabId: incomingHeaders.tabId
|
|
|
|
});
|
2022-10-16 16:08:01 -04:00
|
|
|
popup.then(gotPopup);
|
|
|
|
}
|
2022-02-15 21:15:47 -05:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
resolve({ responseHeaders: incomingHeaders.responseHeaders });
|
2022-10-16 16:08:01 -04:00
|
|
|
}, 2000);
|
|
|
|
});
|
|
|
|
return asyncSetPageAction;
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
2020-08-23 00:22:31 -04:00
|
|
|
|
2020-12-06 02:12:01 -05:00
|
|
|
function getTabURL(tab) {
|
2022-10-16 16:08:01 -04:00
|
|
|
console.log("(scrub)(equiv check) popup check", tab);
|
2021-10-01 15:07:33 -04:00
|
|
|
|
2022-10-16 16:08:01 -04:00
|
|
|
if (tab.id != undefined) {
|
2023-05-25 03:49:17 +00:00
|
|
|
let popup = browser.pageAction.getPopup({ tabId: tab.id });
|
2022-10-16 16:08:01 -04:00
|
|
|
console.log("(scrub)(equiv check) popup check");
|
|
|
|
popup.then(gotPopup);
|
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
}
|
2022-02-15 21:15:47 -05:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function gotPopup(pageTest, tab) {
|
|
|
|
if (pageTest === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.info("pageTest:", pageTest);
|
|
|
|
let isHttps = false;
|
|
|
|
let isI2p = false;
|
|
|
|
if (tab === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isHttps = tab.url.startsWith("https://");
|
|
|
|
isI2p = tab.url.includes(".i2p");
|
|
|
|
if (isHttps) {
|
|
|
|
if (isI2p) {
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tab.id,
|
|
|
|
popup: "security.html"
|
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
path: "icons/infotoopies.png",
|
|
|
|
tabId: tab.id
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
browser.tabs
|
|
|
|
.sendMessage(tab.id, { req: "i2p-torrentlocation" })
|
|
|
|
.then(response => {
|
|
|
|
if (
|
|
|
|
response &&
|
|
|
|
response.content.toUpperCase() !== "NO-ALT-LOCATION"
|
|
|
|
) {
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tab.id,
|
|
|
|
popup: "torrent.html"
|
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
path: "icons/infotoopiesbt.png",
|
|
|
|
tabId: tab.id
|
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: tab.id,
|
|
|
|
title: response.content
|
|
|
|
});
|
|
|
|
browser.pageAction.show(tab.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error("(scrub)(equiv check)", err);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
browser.tabs
|
2023-05-25 03:49:17 +00:00
|
|
|
.sendMessage(tab.id, { req: "i2p-location" })
|
|
|
|
.then(response => {
|
|
|
|
if (
|
|
|
|
response &&
|
|
|
|
response.content.toUpperCase() !== "NO-ALT-LOCATION"
|
|
|
|
) {
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tab.id,
|
|
|
|
popup: "location.html"
|
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
path: "icons/i2plogo.png",
|
|
|
|
tabId: tab.id
|
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: tab.id,
|
|
|
|
title: response.content
|
|
|
|
});
|
|
|
|
browser.pageAction.show(tab.id);
|
2022-10-08 17:21:55 -04:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
});
|
2023-05-25 03:49:17 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error("(scrub)(equiv check)", err);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2020-12-06 13:32:43 -05:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
} else {
|
|
|
|
if (isI2p) {
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tab.id,
|
|
|
|
popup: "security.html"
|
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
path: "icons/infotoopie.png",
|
|
|
|
tabId: tab.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
browser.tabs
|
|
|
|
.sendMessage(tab.id, { req: "i2p-torrentlocation" })
|
|
|
|
.then(response => {
|
|
|
|
if (
|
|
|
|
response &&
|
|
|
|
response.content.toUpperCase() !== "NO-ALT-LOCATION"
|
|
|
|
) {
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
tabId: tab.id,
|
|
|
|
popup: "torrent.html"
|
|
|
|
});
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
path: "icons/infotoopiebt.png",
|
|
|
|
tabId: tab.id
|
|
|
|
});
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
tabId: tab.id,
|
|
|
|
title: response.content
|
|
|
|
});
|
|
|
|
browser.pageAction.show(tab.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error("(pageaction)", err);
|
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2020-12-06 02:12:01 -05:00
|
|
|
}
|
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function getClearTab(tab) {
|
|
|
|
function setupTabs() {
|
|
|
|
if (typeof tab === "number") {
|
|
|
|
browser.tabs.get(tab).then(getTabURL, onScrubError);
|
|
|
|
} else if (typeof tab === "object" && typeof tab.tabId === "number") {
|
|
|
|
browser.tabs.get(tab.tabId).then(getTabURL, onScrubError);
|
|
|
|
} else if (typeof tab === "object" && Array.isArray(tab.tabIds)) {
|
|
|
|
for (let tabId of tab.tabIds) {
|
|
|
|
browser.tabs.get(tabId).then(getTabURL, onScrubError);
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2020-12-06 13:32:43 -05:00
|
|
|
}
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
if (tab === undefined) {
|
2022-10-16 16:08:01 -04:00
|
|
|
browser.tabs.query({}).then(setupTabs);
|
2023-05-25 03:49:17 +00:00
|
|
|
} else {
|
|
|
|
setupTabs();
|
2022-10-16 16:08:01 -04:00
|
|
|
}
|
2020-09-24 20:06:24 -04:00
|
|
|
}
|
|
|
|
|
2020-12-06 02:12:01 -05:00
|
|
|
const filter = {
|
2023-05-25 03:49:17 +00:00
|
|
|
url: [{ hostContains: ".i2p" }]
|
2020-12-06 02:12:01 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
function logOnDOMContentLoaded(details) {
|
2022-10-16 16:08:01 -04:00
|
|
|
console.log(`onDOMContentLoaded: ${details.url}`);
|
2020-12-06 02:12:01 -05:00
|
|
|
}
|
|
|
|
|
2020-09-24 20:06:24 -04:00
|
|
|
browser.tabs.onActivated.addListener(getClearTab);
|
2020-12-06 02:12:01 -05:00
|
|
|
browser.tabs.onAttached.addListener(getClearTab);
|
|
|
|
browser.tabs.onCreated.addListener(getClearTab);
|
|
|
|
browser.tabs.onDetached.addListener(getClearTab);
|
|
|
|
browser.tabs.onHighlighted.addListener(getClearTab);
|
|
|
|
browser.tabs.onMoved.addListener(getClearTab);
|
|
|
|
browser.tabs.onReplaced.addListener(getClearTab);
|
2020-08-23 00:22:31 -04:00
|
|
|
|
2020-12-06 13:32:43 -05:00
|
|
|
browser.pageAction.onClicked.addListener(getClearTab);
|
|
|
|
|
2020-09-21 13:44:26 -04:00
|
|
|
function reloadTabs(tabs) {
|
2022-10-16 16:08:01 -04:00
|
|
|
for (let tab of tabs) {
|
|
|
|
browser.tabs.reload(tab.id);
|
|
|
|
}
|
2020-09-21 13:44:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function reloadError(error) {
|
2022-10-16 16:08:01 -04:00
|
|
|
console.log(`Error: ${error}`);
|
2020-09-21 13:44:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let querying = browser.tabs.query({});
|
2023-05-25 03:49:17 +00:00
|
|
|
querying.then(reloadTabs, onScrubError);
|
2020-09-21 13:44:26 -04:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
/* Listen for onHeaderReceived for the target page.
|
|
|
|
Set "blocking" and "responseHeaders". */
|
2020-08-23 00:22:31 -04:00
|
|
|
browser.webRequest.onHeadersReceived.addListener(
|
2022-10-16 16:08:01 -04:00
|
|
|
coolheadersSetup,
|
2023-05-25 03:49:17 +00:00
|
|
|
{ urls: [
|
|
|
|
"*://*.i2p/*",
|
|
|
|
"https://*/*"
|
|
|
|
] },
|
2022-10-16 16:08:01 -04:00
|
|
|
["responseHeaders"]
|
2020-08-23 00:22:31 -04:00
|
|
|
);
|
|
|
|
|
2020-12-06 13:00:11 -05:00
|
|
|
browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter);
|
2020-12-06 13:32:43 -05:00
|
|
|
browser.webNavigation.onDOMContentLoaded.addListener(
|
2022-10-16 16:08:01 -04:00
|
|
|
logOnDOMContentLoaded,
|
|
|
|
filter
|
2020-12-06 13:32:43 -05:00
|
|
|
);
|
|
|
|
|
2020-12-09 14:36:59 -05:00
|
|
|
browser.webRequest.onBeforeRequest.addListener(contextSetup, {
|
2023-05-25 03:49:17 +00:00
|
|
|
urls: [
|
|
|
|
"*://*.i2p/*",
|
|
|
|
"*://localhost/*",
|
|
|
|
"*://127.0.0.1/*",
|
|
|
|
"*://*/*i2p*"
|
|
|
|
]
|
2020-12-09 14:36:59 -05:00
|
|
|
});
|
2019-10-07 20:52:03 -04:00
|
|
|
|
2019-10-06 13:58:26 -04:00
|
|
|
browser.webRequest.onBeforeSendHeaders.addListener(
|
2022-10-16 16:08:01 -04:00
|
|
|
contextScrub,
|
|
|
|
{ urls: ["*://*.i2p/*"] },
|
|
|
|
["requestHeaders"]
|
2022-10-08 17:35:07 -04:00
|
|
|
);
|
2023-05-25 03:49:17 +00:00
|
|
|
|
|
|
|
function onScrubError(err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onContextGotLog(log) {
|
|
|
|
console.log(log);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onContextError(err) {
|
|
|
|
console.error("Context launcher error:", err);
|
|
|
|
}
|