Files
I2P_in_Private_Browsing_Mod…/scrub.js

791 lines
27 KiB
JavaScript
Raw Normal View History

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");
var contextScrub = requestDetails => {
function onHeaderError() {
2022-10-24 19:57:51 -04:00
console.log("Header scrub error");
}
try {
2022-10-24 19:57:51 -04:00
var headerScrub = function (context) {
var ua = "MYOB/6.66 (AN/ON)";
if (!context) {
} else if (context.name == titlepref) {
for (var header of requestDetails.requestHeaders) {
2022-10-24 19:57:51 -04:00
if (header.name.toLowerCase() === "user-agent") {
header.value = ua;
}
2022-10-08 17:21:55 -04:00
}
return {
2022-10-24 19:57:51 -04:00
requestHeaders: requestDetails.requestHeaders,
};
}
};
2022-10-24 19:57:51 -04:00
var contextGet = async function (tabInfo) {
try {
//console.log("(scrub)Tab info from Function", tabInfo);
let context = await browser.contextualIdentities.get(
tabInfo.cookieStoreId
);
return context;
} catch (error) {
return undefined;
}
};
2022-10-24 19:57:51 -04:00
var tabGet = async function (tabId) {
try {
//console.log("(scrub)Tab ID from Request", tabId);
let tabInfo = await browser.tabs.get(tabId);
return tabInfo;
} catch (error) {
return undefined;
}
};
if (requestDetails.tabId > 0) {
tab = tabGet(requestDetails.tabId);
context = tab.then(contextGet, onHeaderError);
req = context.then(headerScrub, onHeaderError);
//console.log("(scrub)Scrubbing I2P Request", req);
return req;
}
} catch (error) {
2022-10-24 19:57:51 -04:00
console.log("(scrub)Not scrubbing non-I2P request.", error);
}
2022-10-24 19:57:51 -04:00
};
2022-10-24 19:57:51 -04:00
var notMyContextNotMyProblem = async function () {
var contexts = await browser.contextualIdentities.query({});
var context1 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: titlepref,
});
var context2 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: routerpref,
});
var context3 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: mailpref,
});
var context4 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: torrentpref,
});
var context5 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: tunnelpref,
});
var context6 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: ircpref,
});
var context7 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: muwirepref,
});
var context8 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: botepref,
});
var context9 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: blogpref,
});
var context10 = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: torpref,
});
var othercontexts = [];
2022-10-24 19:57:51 -04:00
console.log("Contexts:", contexts);
for (context in contexts) {
if (
contexts[context].cookieStoreId == context1[0].cookieStoreId ||
contexts[context].cookieStoreId == context2[0].cookieStoreId ||
contexts[context].cookieStoreId == context3[0].cookieStoreId ||
contexts[context].cookieStoreId == context4[0].cookieStoreId ||
contexts[context].cookieStoreId == context5[0].cookieStoreId ||
contexts[context].cookieStoreId == context6[0].cookieStoreId ||
contexts[context].cookieStoreId == context7[0].cookieStoreId ||
contexts[context].cookieStoreId == context8[0].cookieStoreId ||
contexts[context].cookieStoreId == context9[0].cookieStoreId ||
contexts[context].cookieStoreId == context10[0].cookieStoreId
) {
console.log(
2022-10-24 19:57:51 -04:00
"Context found",
contexts[context].cookieStoreId,
2022-10-24 19:57:51 -04:00
"is my responsibility"
);
} else {
//console.log("Context found", contexts[context].cookieStoreId, "is not my responsibility")
othercontexts.push(contexts[context]);
2020-03-02 17:34:39 -05:00
}
}
return othercontexts;
2022-10-24 19:57:51 -04:00
};
2020-03-02 17:34:39 -05:00
2022-10-24 19:57:51 -04:00
var contextSetup = function (requestDetails) {
function onContextError() {
2022-10-24 19:57:51 -04:00
console.error("Context launcher error");
}
async function forceIntoIsolation(tabId, contextidentifier, tab, pin = true) {
console.info(
2022-10-24 19:57:51 -04:00
"(isolate) forcing context for",
tabId,
contextidentifier,
tab
);
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: contextidentifier,
});
if (tabId.cookieStoreId != context[0].cookieStoreId) {
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",
tabId.id,
2022-10-24 19:57:51 -04:00
"in favor of",
tab.id,
2022-10-24 19:57:51 -04:00
"with context",
tab.cookieStoreId
);
browser.tabs.remove(tabId.id);
if (pin) {
browser.tabs.move(tab.id, { index: 0 });
for (index = 0; index < tabs.length; index++) {
if (index != tabs.length - 1)
browser.tabs.remove(tabs[index].id);
}
}
}
browser.pageAction.setPopup({
tabId: tabId.id,
2022-10-24 19:57:51 -04:00
popup: "security.html",
});
browser.pageAction.show(tabId.id);
}
var pins = browser.tabs.query({
2022-10-24 19:57:51 -04:00
cookieStoreId: context[0].cookieStoreId,
});
pins.then(closeOldTab, onError);
// closeOldTab(tab);
}
var created = browser.tabs.create({
active: true,
cookieStoreId: context[0].cookieStoreId,
url: requestDetails.url,
2022-10-24 19:57:51 -04:00
pinned: pin,
});
created.then(onCreated, onContextError);
}
var gettab = browser.tabs.get(tabId.id);
gettab.then(Create, onContextError);
return tabId;
}
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
}
try {
2022-10-24 19:57:51 -04:00
var i2pTabFind = async function (tabId) {
console.info("(isolate)Context Discovery browser");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: titlepref,
});
return forceIntoIsolation(tabId, titlepref, tab, false);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var routerTabFind = async function (tabId) {
console.info("(isolate)Context Discovery console");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: routerpref,
});
return forceIntoIsolation(tabId, routerpref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var i2ptunnelTabFind = async function (tabId) {
console.info("(isolate)Context Discovery browser");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: tunnelpref,
});
return forceIntoIsolation(tabId, tunnelpref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var snarkTabFind = async function (tabId) {
console.info("(isolate)Context Discovery torrents");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: torrentpref,
});
if (tabId.cookieStoreId != context[0].cookieStoreId) {
var exemptContext = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: titlepref,
});
let tmp = new URL(tabId.url);
2022-10-24 19:57:51 -04:00
console.log("(isolate)tabid host", tmp.host);
if (!requestDetails.url.includes("snark/" + tmp.host)) {
// if (tabId.cookieStoreId != exemptContext[0].cookieStoreId){
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",
tabId.id,
2022-10-24 19:57:51 -04:00
"in favor of",
tab.id,
2022-10-24 19:57:51 -04:00
"with context",
tab.cookieStoreId
);
browser.tabs.remove(tabId.id);
browser.tabs.move(tab.id, { index: 0 });
}
for (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
}
var pins = browser.tabs.query({
2022-10-24 19:57:51 -04:00
cookieStoreId: context[0].cookieStoreId,
2022-02-15 21:15:47 -05:00
});
pins.then(closeOldTab, onError);
}
2022-10-24 19:57:51 -04:00
if (requestDetails.url.endsWith("xhr1.html")) {
hostname = url.split("/")[2];
let prefix = url.substr(0, url.indexOf("://") + 3);
requestDetails.url = prefix + hostname + "/i2psnark/";
}
var created = browser.tabs.create({
active: true,
pinned: true,
cookieStoreId: context[0].cookieStoreId,
2022-10-24 19:57:51 -04:00
url: requestDetails.url,
});
created.then(onCreated, onContextError);
}
var gettab = browser.tabs.get(tabId.id);
gettab.then(Create, onContextError);
return tabId;
}
2022-10-07 19:32:52 -04:00
}
} catch (error) {
2022-10-24 19:57:51 -04:00
console.log("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var muwireTabFind = async function (tabId) {
console.info("(isolate)Context Discovery muwire");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: muwirepref,
});
return forceIntoIsolation(tabId, muwirepref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var i2pboteTabFind = async function (tabId) {
console.info("(isolate)Context Discovery bote");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: botepref,
});
return forceIntoIsolation(tabId, botepref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var mailTabFind = async function (tabId) {
console.info("(isolate)Context Discovery mail");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: mailpref,
});
return forceIntoIsolation(tabId, mailpref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var ircTabFind = async function (tabId) {
console.info("(isolate)Context Discovery irc");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: ircpref,
});
return forceIntoIsolation(tabId, ircpref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var torTabFind = async function (tabId) {
console.info("(isolate)Context Discovery tor");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: torpref,
});
return forceIntoIsolation(tabId, torpref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var blogTabFind = async function (tabId) {
console.info("(isolate)Context Discovery blog");
try {
var context = await browser.contextualIdentities.query({
2022-10-24 19:57:51 -04:00
name: blogpref,
});
return forceIntoIsolation(tabId, blogpref, tab);
} catch (error) {
2022-10-24 19:57:51 -04:00
console.error("(isolate)Context Error", error);
}
};
2022-10-24 19:57:51 -04:00
var tabGet = async function (tabId) {
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);
}
};
if (requestDetails == undefined) {
return requestDetails;
}
if (proxyHost(requestDetails)) {
setcookie = browser.cookies.set({
firstPartyDomain: i2pHostName(requestDetails.url),
url: requestDetails.url,
2022-10-24 19:57:51 -04:00
secure: true,
});
setcookie.then(onContextGotLog, onContextError);
return requestDetails;
}
2022-10-07 19:32:52 -04:00
if (requestDetails.tabId > 0) {
var tab = tabGet(requestDetails.tabId);
tab.then(isolate);
2022-10-08 17:21:55 -04:00
function isolate(oldtab) {
let localhost = localHost(requestDetails.url);
let routerhost = routerHost(requestDetails.url);
if (routerhost) {
2022-10-24 19:57:51 -04:00
if (routerhost === "i2ptunnelmgr") {
var tunneltab = tab.then(i2ptunnelTabFind, onContextError);
return requestDetails;
2022-10-24 19:57:51 -04:00
} else if (routerhost === "i2psnark") {
var snarktab = tab.then(snarkTabFind, onContextError);
return requestDetails;
2022-10-24 19:57:51 -04:00
} else if (routerhost === "webmail") {
var mailtab = tab.then(mailTabFind, onContextError);
return requestDetails;
2022-10-24 19:57:51 -04:00
} else if (routerhost === "muwire") {
var routertab = tab.then(muwireTabFind, onContextError);
return requestDetails;
2022-10-24 19:57:51 -04:00
} else if (routerhost === "i2pbote") {
var routertab = tab.then(i2pboteTabFind, onContextError);
return requestDetails;
2022-10-24 19:57:51 -04:00
} else if (routerhost === "routerconsole") {
var routertab = tab.then(routerTabFind, onContextError);
return requestDetails;
}
} else {
if (localhost) {
2022-10-24 19:57:51 -04:00
if (localhost === "blog") {
var routertab = tab.then(blogTabFind, onContextError);
return requestDetails;
2022-10-24 19:57:51 -04:00
} else if (localhost === "irc") {
var irctab = tab.then(ircTabFind, onContextError);
return requestDetails;
2022-10-24 19:57:51 -04:00
} else if (localhost === "tor") {
var tortab = tab.then(torTabFind, onContextError);
return requestDetails;
2022-10-08 17:21:55 -04:00
}
}
2022-10-08 17:21:55 -04:00
}
// if (oldtab.cookieStoreId == 'firefox-default') {
if (i2pHost(requestDetails)) {
var thn = i2pHostName(requestDetails.url);
2022-10-24 19:57:51 -04:00
if (requestDetails.url.includes("=" + thn)) {
if (
2022-10-24 19:57:51 -04:00
!requestDetails.url.includes("://github.com") ||
!requestDetails.url.includes("://notabug.org") ||
!requestDetails.url.includes("://i2pgit.org") ||
!requestDetails.url.includes("://gitlab.com")
) {
if (!localhost) {
2022-10-24 19:57:51 -04:00
console.log("(scrub)checking search hostnames =" + thn);
var tpt = requestDetails.url.split("=" + thn, 2);
requestDetails.url =
2022-10-24 19:57:51 -04:00
"http://" + thn + "/" + tpt[1].replace("%2F", "");
}
}
}
2022-10-24 19:57:51 -04:00
console.log("(scrub) new hostname", requestDetails.url);
var setcookie = browser.cookies.set({
firstPartyDomain: i2pHostName(requestDetails.url),
url: requestDetails.url,
2022-10-24 19:57:51 -04:00
secure: true,
});
setcookie.then(onContextGotLog, onContextError);
if (!routerhost) {
var i2ptab = tab.then(i2pTabFind, onContextError);
}
return requestDetails;
}
if (extensionHost(requestDetails)) {
return requestDetails;
}
//}
}
}
} catch (error) {
2022-10-24 19:57:51 -04:00
console.log("(isolate)Not an I2P request, blackholing", error);
}
2019-10-06 15:18:10 -04:00
};
2022-10-24 19:57:51 -04:00
var coolheadersSetup = function (e) {
var asyncSetPageAction = new Promise((resolve, reject) => {
window.setTimeout(() => {
if (e.tabId != undefined) {
popup = browser.pageAction.getPopup({ tabId: e.tabId });
popup.then(gotPopup);
}
2022-02-15 21:15:47 -05:00
function gotPopup(p) {
2022-10-24 19:57:51 -04:00
console.log("(scrub)(header check) checking popup", p);
console.log(
2022-10-24 19:57:51 -04:00
"(scrub)(header check) checking headers",
e.responseHeaders
);
let headers = e.responseHeaders.filter((word) =>
2022-10-24 19:57:51 -04:00
word.name.toUpperCase().includes("I2P")
);
2022-10-24 19:57:51 -04:00
console.log("(scrub)(header check) checking filtered headers", headers);
for (i = headers.length - 1; i >= 0; i--) {
let header = headers[i];
2022-10-24 19:57:51 -04:00
console.log("(scrub)(header check) checking header", header);
if (header.name.toUpperCase().endsWith("I2P-LOCATION")) {
var tab = browser.tabs.get(e.tabId);
tab.then(altSrc);
2022-02-15 21:15:47 -05:00
function altSrc(tab) {
2022-10-24 19:57:51 -04:00
console.log("(scrub) X-I2P-LOCATION", header.value);
let url = new URL(header.value);
browser.pageAction.setPopup({
tabId: e.tabId,
2022-10-24 19:57:51 -04:00
popup: "location.html",
});
browser.pageAction.setIcon({
2022-10-24 19:57:51 -04:00
path: "icons/i2plogo.png",
tabId: e.tabId,
});
let eurl = new URL(tab.url);
browser.pageAction.setTitle({
tabId: e.tabId,
2022-10-24 19:57:51 -04:00
title: "http://" + url.host + eurl.pathname,
});
browser.pageAction.show(e.tabId);
}
break;
}
2022-10-24 19:57:51 -04:00
if (header.name.toUpperCase().endsWith("I2P-TORRENTLOCATION")) {
console.log(
2022-10-24 19:57:51 -04:00
"(scrub)(header check) checking header torrentlocation",
header
);
2022-10-24 19:57:51 -04:00
var imgs = document.getElementsByTagName("img");
for (let img of imgs) {
if (tmpsrc.host == location.host) {
img.src =
2022-10-24 19:57:51 -04:00
"http://127.0.0.1:7657/i2psnark/" +
tmpsrc.host +
tmpsrc.pathname;
2022-10-24 19:57:51 -04:00
img.onerror = function () {
img.src = tmpsrc;
};
}
}
2022-10-24 19:57:51 -04:00
var videos = document.getElementsByTagName("video");
for (let video of videos) {
let tmpsrc = new URL(video.currentSrc);
if (tmpsrc.host == location.host) {
2022-10-24 19:57:51 -04:00
if (!video.innerHTML.includes("127.0.0.1")) {
innerHTML = video.innerHTML;
topInnerHTML = video.innerHTML.replace(
'src="',
2022-10-24 19:57:51 -04:00
'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/"
);
video.innerHTML = topInnerHTML; // + innerHTML;
2022-10-24 19:57:51 -04:00
video.onerror = function () {
video.innerHTML = topInnerHTML + innerHTML;
};
}
}
}
2022-10-24 19:57:51 -04:00
var audios = document.getElementsByTagName("audio");
for (let audio of audios) {
let tmpsrc = new URL(audio.currentSrc);
if (tmpsrc.host == location.host) {
2022-10-24 19:57:51 -04:00
if (!audio.innerHTML.includes("127.0.0.1")) {
innerHTML = audio.innerHTML;
topInnerHTML = audio.innerHTML.replace(
'src="',
2022-10-24 19:57:51 -04:00
'src="http://127.0.0.1:7657/i2psnark/' + location.host + "/"
);
audio.innerHTML = topInnerHTML; // + innerHTML;
2022-10-24 19:57:51 -04:00
audio.onerror = function () {
audio.innerHTML = topInnerHTML + innerHTML;
};
2020-12-11 20:47:49 -05:00
}
}
}
browser.pageAction.setPopup({
tabId: e.tabId,
2022-10-24 19:57:51 -04:00
popup: "torrent.html",
});
2022-10-24 19:57:51 -04:00
if (tab != undefined && tab.url.startsWith("https")) {
browser.pageAction.setIcon({
2022-10-24 19:57:51 -04:00
path: "icons/infotoopiesbt.png",
tabId: e.tabId,
});
} else {
browser.pageAction.setIcon({
2022-10-24 19:57:51 -04:00
path: "icons/infotoopiebt.png",
tabId: e.tabId,
});
}
browser.pageAction.setTitle({
tabId: e.tabId,
2022-10-24 19:57:51 -04:00
title: header.value,
});
browser.pageAction.show(e.tabId);
break;
}
}
}
resolve({ responseHeaders: e.responseHeaders });
}, 2000);
});
return asyncSetPageAction;
2020-11-10 21:48:08 -05:00
};
function getTabURL(tab) {
console.log("(scrub)(equiv check) popup check", tab);
2021-10-01 15:07:33 -04:00
if (tab.id != undefined) {
popup = browser.pageAction.getPopup({ tabId: tab.id });
console.log("(scrub)(equiv check) popup check");
popup.then(gotPopup);
}
2022-02-15 21:15:47 -05:00
function gotPopup(p) {
if (p.length != 0) return;
if (tab.url.startsWith("https")) {
if (tab.url.includes(".i2p")) {
browser.pageAction.setPopup({
tabId: tab.id,
popup: "security.html",
});
browser.pageAction.setIcon({
path: "icons/infotoopies.png",
tabId: tab.id,
});
console.log(tab.url);
//console.log("(background) tabinfo", tabInfo[0].id)
try {
browser.tabs
.sendMessage(tab.id, { req: "i2p-torrentlocation" })
.then((response) => {
if (response != undefined && response != "") {
console.log(
"(scrub)(equiv check) i2p-torrentlocation response object",
response
);
if (response.content.toUpperCase() != "NO-ALT-LOCATION") {
browser.pageAction.setPopup({
2021-10-01 14:16:15 -04:00
tabId: tab.id,
popup: "torrent.html",
});
browser.pageAction.setIcon({
path: "icons/infotoopiesbt.png",
2022-10-07 19:32:52 -04:00
tabId: tab.id,
});
browser.pageAction.setTitle({
tabId: tab.id,
title: response.content,
});
browser.pageAction.show(tab.id);
2021-10-01 14:16:15 -04:00
}
}
});
console.log("(scrub)(equiv check)", tab.id, tab.url);
} catch (e) {
console.log("(scrub)(equiv check)", e);
}
} else {
try {
browser.tabs
.sendMessage(tab.id, { req: "i2p-location" })
.then((response) => {
if (response != undefined) {
console.log(
"(scrub)(equiv check) i2p-location response object",
response
);
if (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);
2021-10-01 14:16:15 -04:00
}
}
});
console.log("(scrub)(equiv check)", tab.id, tab.url);
} catch (e) {
console.log("(scrub)(equiv check)", e);
}
}
} else {
if (tab.url.includes(".i2p")) {
browser.pageAction.setPopup({
tabId: tab.id,
popup: "security.html",
});
browser.pageAction.setIcon({
path: "icons/infotoopie.png",
tabId: tab.id,
});
console.log(tab.url);
}
try {
browser.tabs
.sendMessage(tab.id, { req: "i2p-torrentlocation" })
.then((response) => {
if (response != undefined) {
console.log(
"(pageaction) i2p-torrentlocation response object",
response
);
if (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,
2022-10-07 19:32:52 -04:00
});
browser.pageAction.setTitle({
tabId: tab.id,
title: response.content,
});
browser.pageAction.show(tab.id);
}
2022-10-08 17:21:55 -04:00
}
});
console.log("(pageaction)", tab.id, tab.url);
} catch (e) {
console.log("(pageaction)", e);
}
}
}
}
function getClearTab(tobj) {
function setupTabs(tobj) {
if (typeof tobj == "number") {
browser.tabs.get(tobj).then(getTabURL, onError);
}
if (typeof tobj.tabId == "number") {
console.log("(scrub) tobj", tobj);
browser.tabs.get(tobj.tabId).then(getTabURL, onError);
} else {
for (let tab in tobj.tabIds) {
console.log("(scrub) tab", tobj.tabIds[tab]);
browser.tabs.get(tobj.tabIds[tab]).then(getTabURL, onError);
}
}
}
if (tobj != undefined) {
setupTabs(tobj);
} else {
browser.tabs.query({}).then(setupTabs);
}
2020-09-24 20:06:24 -04:00
}
const filter = {
url: [{ hostContains: ".i2p" }],
};
function logOnDOMContentLoaded(details) {
console.log(`onDOMContentLoaded: ${details.url}`);
}
2020-09-24 20:06:24 -04:00
browser.tabs.onActivated.addListener(getClearTab);
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);
browser.pageAction.onClicked.addListener(getClearTab);
function reloadTabs(tabs) {
for (let tab of tabs) {
browser.tabs.reload(tab.id);
}
}
function reloadError(error) {
console.log(`Error: ${error}`);
}
let querying = browser.tabs.query({});
querying.then(reloadTabs, onError);
// Listen for onHeaderReceived for the target page.
// Set "blocking" and "responseHeaders".
browser.webRequest.onHeadersReceived.addListener(
coolheadersSetup,
{ urls: ["*://*.i2p/*", "https://*/*"] },
["responseHeaders"]
);
browser.webNavigation.onDOMContentLoaded.addListener(getClearTab, filter);
browser.webNavigation.onDOMContentLoaded.addListener(
logOnDOMContentLoaded,
filter
);
browser.webRequest.onBeforeRequest.addListener(contextSetup, {
urls: ["*://*.i2p/*", "*://localhost/*", "*://127.0.0.1/*", "*://*/*i2p*"],
});
browser.webRequest.onBeforeSendHeaders.addListener(
contextScrub,
{ urls: ["*://*.i2p/*"] },
["requestHeaders"]
2022-10-08 17:35:07 -04:00
);