Files
I2P_in_Private_Browsing_Mod…/info.js

388 lines
10 KiB
JavaScript
Raw Normal View History

2022-10-24 19:57:51 -04:00
var titlepref = chrome.i18n.getMessage("titlePreface");
2022-10-05 17:10:53 -04:00
function checkPeerConnection() {
let getting = browser.privacy.network.peerConnectionEnabled.get({});
getting.then((got) => {
let webrtc = got.value;
2023-06-20 15:24:37 -04:00
console.log("(info) checking webrtc", webrtc);
2022-10-24 19:57:51 -04:00
if (document.getElementById("enable-web-rtc") !== null)
document.getElementById("enable-web-rtc").checked = webrtc;
});
}
checkPeerConnection();
2020-01-12 01:18:26 -05:00
function checkSnowflake() {
try {
function snowflake(snowflake) {
2023-06-20 15:24:37 -04:00
console.log(
"(info) snowflake plugin found, leaving WebRTC alone",
snowflake
);
AssurePeerConnection();
2020-01-11 23:14:58 -05:00
}
var snowflakeInfo = browser.management.get(
"{b11bea1f-a888-4332-8d8a-cec2be7d24b9}"
);
snowflakeInfo.then(snowflake);
} catch (err) {
2023-06-20 15:24:37 -04:00
console.log("(info) snowflake not found", err);
}
2020-01-11 23:14:58 -05:00
}
2020-01-12 01:18:26 -05:00
checkSnowflake();
2020-01-11 23:14:58 -05:00
function checkHistory() {
let getting = browser.storage.local.get("disable_history");
getting.then((got) => {
let disable_history = got.disable_history;
if (disable_history == undefined) {
disable_history = false;
}
2023-06-20 15:24:37 -04:00
console.log("(info) checking history", disable_history);
if (document.getElementById("disable-history") !== null)
document.getElementById("disable-history").checked = disable_history;
});
}
checkHistory();
2023-06-20 15:24:37 -04:00
document.addEventListener("click", clickHandler);
function clickHandler(clickEvent) {
const targetId = clickEvent.target.id;
if (
targetId === "window-create-help-panel" ||
targetId === "window-create-news-panel"
) {
const createData = { type: "panel", incognito: true };
browser.tabs.create(createData).then(() => {
console.log(`The ${targetId.split("-")[2]} panel has been created`);
});
2023-06-20 15:24:37 -04:00
} else if (targetId === "visit-irc") {
browser.sidebarAction.setPanel({ panel: "http://127.0.0.1:7669" });
browser.sidebarAction.open();
2023-06-20 15:24:37 -04:00
} else if (targetId === "generate-fresh-tunnel") {
function refreshIdentity() {
2023-06-20 15:24:37 -04:00
console.log("(info) Generating new identity");
const Http = new XMLHttpRequest();
2023-06-20 15:24:37 -04:00
const url = `http://${controlHost}:${controlPort}`;
Http.open("GET", url);
Http.send();
2023-06-20 15:24:37 -04:00
Http.onreadystatechange = () => {
console.log(Http.responseText);
};
}
refreshIdentity();
2023-06-20 15:24:37 -04:00
} else if (targetId.startsWith("label-router")) {
const listId = `label-${targetId.split("-")[2]}-list`;
const list = document.getElementById(listId);
if (list.style.display !== "none") {
console.log(`hiding ${listId}`);
list.style.display = "none";
} else {
2023-06-20 15:24:37 -04:00
console.log(`showing ${listId}`);
list.style.display = "block";
}
2023-06-20 15:24:37 -04:00
} else if (targetId === "search-submit") {
console.log("(info) attempting to create search tab");
goSearch();
2023-06-20 15:24:37 -04:00
} else if (targetId === "url-submit") {
console.log("(info) attempting to create search tab");
goURL();
2023-06-20 15:24:37 -04:00
} else if (targetId === "browser-action") {
console.log("(info) showing a browser action");
showBrowsing();
2023-06-20 15:24:37 -04:00
} else if (targetId === "torrent-action" || targetId === "torrentui-opener") {
console.log("(info) showing a torrent action");
showTorrentsMenu();
2023-06-20 15:24:37 -04:00
} else if (targetId.startsWith("window-visit")) {
const page = targetId.split("-")[2];
console.log(`attempting to create ${page} tab`);
switch (page) {
case "homepage":
case "help":
goHome();
break;
case "index":
goIndex();
break;
case "torrent":
goTorrent();
break;
case "console":
goConsole();
break;
case "toopie":
goToopie();
break;
case "i2ptunnel":
goTunnel();
break;
case "i2p":
goHomepage();
break;
case "susimail":
goMail();
break;
case "snark":
goSnark();
break;
2020-09-09 23:23:02 -04:00
}
2023-06-20 15:24:37 -04:00
} else if (targetId === "clear-browser-data") {
forgetBrowsingData();
} else if (targetId === "enable-web-rtc") {
const isWebRTCEnabled = clickEvent.target.checked;
browser.runtime.sendMessage({
rtc: isWebRTCEnabled ? "enableWebRTC" : "disableWebRTC",
});
checkPeerConnection();
return;
2023-06-20 15:24:37 -04:00
} else if (targetId === "disable-history") {
const isHistoryEnabled = !clickEvent.target.checked;
browser.runtime.sendMessage({
history: isHistoryEnabled ? "enableHistory" : "disableHistory",
});
return;
}
2019-03-13 17:50:51 -04:00
clickEvent.preventDefault();
2023-06-20 15:24:37 -04:00
}
2019-11-10 22:24:10 -05:00
window.onload = function (e) {
if (document.getElementById("label-peers-list") != null) {
document.getElementById("label-peers-list").style.display = "none";
}
if (document.getElementById("label-bandwidth-list") != null) {
document.getElementById("label-bandwidth-list").style.display = "none";
}
2020-11-10 21:48:08 -05:00
};
2020-09-09 23:23:02 -04:00
2019-11-10 22:24:10 -05:00
function proxyReadiness() {
console.log(this.responseText);
2019-11-10 22:24:10 -05:00
}
var gettingInfo = browser.runtime.getPlatformInfo();
2020-11-10 21:48:08 -05:00
gettingInfo.then((got) => {
if (got.os != "android") {
browser.history.onVisited.addListener(onVisited);
}
});
function showBrowsing() {
var x = document.getElementById("browserpanel");
x.style.display = "block";
var y = document.getElementById("torrentpanel");
y.style.display = "none";
2020-01-14 17:46:26 -05:00
}
function showTorrentsMenu() {
var x = document.getElementById("browserpanel");
x.style.display = "none";
var y = document.getElementById("torrentpanel");
y.style.display = "block";
2020-01-14 17:46:26 -05:00
}
function goHome() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Help tab not created");
}
2023-06-20 15:24:37 -04:00
let createData = {
url: "home.html",
};
console.log("(info) visiting homepage");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
}
2020-01-11 22:32:25 -05:00
function goIndex() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Help tab not created");
}
let createData = {
url: "index.html",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting help");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2020-01-11 22:32:25 -05:00
}
function goTorrent() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Torrent Help tab not created");
}
let createData = {
url: "torrent/index.html",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting torrent help");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
}
2022-10-03 02:04:28 -04:00
function goHomepage() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) i2p-projekt tab not created");
}
let createData = {
url: "http://i2p-projekt.i2p",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting i2p-projekt");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2022-10-03 02:04:28 -04:00
}
function goHelp() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Torrent Help tab not created");
}
let createData = {
url: "i2pcontrol/index.html",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting torrent help");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
}
2020-01-12 18:01:25 -05:00
function goToopie() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Toopie tab created");
}
2023-06-20 15:24:37 -04:00
console.log("(info) visiting toopie");
let creating = browser.sidebarAction.open();
browser.sidebarAction.setPanel({
panel: browser.runtime.getURL("/toopie.html"),
});
creating.then(onTabCreated, onTabError);
2020-01-12 18:01:25 -05:00
}
function onTabCreated() {
2023-06-20 15:24:37 -04:00
console.log("(info) Tab Created");
2019-11-22 17:49:27 -05:00
}
2020-01-11 22:01:37 -05:00
function goSearch() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Search tab created");
}
let createData = {
url:
"http://cuss2sgthm5wfipnnztrjdvtaczb22hnmr2ohnaqqqz3jf6ubf3a.b32.i2p/yacysearch.html?" +
"query=" +
document.getElementById("search-query").value,
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting legwork");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2022-10-16 14:49:32 -04:00
}
function goURL() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Search tab created");
}
2022-10-16 14:49:32 -04:00
function createNewURLTab(context) {
2023-06-20 15:24:37 -04:00
console.log("(info) visiting URL");
let createData = {
url: document.getElementById("url-query").value,
cookieStoreId: context[0].cookieStoreId,
};
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
}
let context = browser.contextualIdentities.query({
name: titlepref,
});
context.then(createNewURLTab, onTabError);
2022-10-05 17:10:53 -04:00
}
function routerAddr() {
2023-06-20 15:24:37 -04:00
try {
return control_host() + ":" + control_port();
} catch {
return "127.0.0.1:7657";
}
}
2022-09-30 16:16:03 -04:00
function goConsole() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Console tab not created");
}
let createData = {
url: "http://" + routerAddr() + "/home",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting router console");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2022-09-30 16:16:03 -04:00
}
2019-11-22 17:49:27 -05:00
function goTunnel() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) I2PTunnel tab created");
}
let createData = {
url: "http://" + routerAddr() + "/i2ptunnel",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting i2ptunnel");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2019-11-22 17:49:27 -05:00
}
function goMail() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Mail tab created");
}
let createData = {
url: "http://" + routerAddr() + "/susimail",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting mail");
let creating = browser.tabs.create(createData);
creating(onTabCreated, onTabError);
2019-11-22 17:49:27 -05:00
}
function goSnark() {
function onTabError() {
2023-06-20 15:24:37 -04:00
console.log("(info) Snark tab created");
}
let createData = {
url: "http://" + routerAddr() + "/i2psnark",
};
2023-06-20 15:24:37 -04:00
console.log("(info) visiting snark");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
}
2019-11-10 22:24:10 -05:00
function onVisited(historyItem) {
function onCleaned(results) {
if (results.length) {
2023-06-20 15:24:37 -04:00
console.log("(info) was not removed");
} else {
2023-06-20 15:24:37 -04:00
console.log("(info) was removed");
}
}
2019-11-10 22:24:10 -05:00
function onRemoved() {
var searching = browser.history.search({
text: historyItem.url,
startTime: 0,
});
searching.then(onCleaned);
}
if (!history) {
if (i2pHost(historyItem)) {
var deletingUrl = browser.history.deleteUrl(historyItem.url);
2019-12-24 16:51:38 -05:00
}
deletingUrl.then(onRemoved);
}
2019-11-10 22:24:10 -05:00
}
2022-10-16 14:49:32 -04:00
/*
2020-01-22 21:18:11 -05:00
if (UpdateContents !== undefined) UpdateContents();
2022-10-16 14:49:32 -04:00
*/
const minutes = 0.2;
const interval = minutes * 60 * 1000;
setInterval(function () {
if (UpdateContents !== undefined) UpdateContents();
2022-10-07 19:32:52 -04:00
}, interval);