Files
I2P_in_Private_Browsing_Mod…/info.js

350 lines
10 KiB
JavaScript
Raw Normal View History

function checkPeerConnection() {
let getting = browser.privacy.network.peerConnectionEnabled.get({});
2020-11-10 21:48:08 -05:00
getting.then((got) => {
let webrtc = got.value;
2021-01-31 01:07:14 -05:00
console.log("checking webrtc", webrtc);
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() {
2020-01-11 23:14:58 -05:00
try {
function snowflake(snowflake) {
console.log("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}" // string
);
snowflakeInfo.then(snowflake);
2020-01-12 01:18:26 -05:00
} catch {
console.log("snowflake not found");
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");
2020-11-10 21:48:08 -05:00
getting.then((got) => {
let disable_history = got.disable_history;
2019-12-24 11:21:07 -05:00
if (disable_history == undefined) {
2019-12-24 16:51:38 -05:00
disable_history = false;
}
console.log("checking history", disable_history);
2020-01-22 21:18:11 -05:00
if (document.getElementById("disable-history") !== null)
document.getElementById("disable-history").checked = disable_history;
});
}
checkHistory();
2020-11-10 21:48:08 -05:00
document.addEventListener("click", (clickEvent) => {
if (clickEvent.target.id === "window-create-help-panel") {
let createData = {
type: "panel",
2020-11-10 21:48:08 -05:00
incognito: true,
};
let creating = browser.tabs.create(createData);
creating.then(() => {
console.log("The help panel has been created");
});
} else if (clickEvent.target.id === "window-create-news-panel") {
let createData = {
type: "panel",
2020-11-10 21:48:08 -05:00
incognito: true,
};
let creating = browser.tabs.create(createData);
creating.then(() => {
console.log("The news panel has been created");
});
2020-12-03 13:17:06 -05:00
} else if (clickEvent.target.id === "visit-irc") {
browser.sidebarAction.setPanel({ panel: "http://127.0.0.1:7669" });
browser.sidebarAction.open();
} else if (clickEvent.target.id === "generate-fresh-tunnel") {
function refreshIdentity() {
2019-10-06 15:18:10 -04:00
console.log("Generating new identity");
const Http = new XMLHttpRequest();
2019-10-06 15:18:10 -04:00
const url = "http://" + controlHost + ":" + controlPort;
Http.open("GET", url);
Http.send();
2020-11-10 21:48:08 -05:00
Http.onreadystatechange = (event) => {
2019-10-06 15:18:10 -04:00
console.log(Http.responseText);
};
2019-03-13 19:38:34 -04:00
}
refreshIdentity();
} else if (clickEvent.target.id === "label-router-restart") {
console.log("attempting to initiate graceful restart");
RouterManager("RestartGraceful");
} else if (clickEvent.target.id === "label-router-shutdown") {
console.log("attempting to initiate graceful shutdown");
RouterManager("ShutdownGraceful");
2020-09-09 23:23:02 -04:00
} else if (clickEvent.target.id === "label-router-status") {
2020-11-10 21:48:08 -05:00
if (document.getElementById("label-status-list").style.display !== "none") {
2020-09-09 23:23:02 -04:00
console.log("hiding label-status-list");
2020-11-10 21:48:08 -05:00
document.getElementById("label-status-list").style.display = "none";
} else {
2020-09-09 23:23:02 -04:00
console.log("showing label-status-list");
2020-11-10 21:48:08 -05:00
document.getElementById("label-status-list").style.display = "block";
2020-09-09 23:23:02 -04:00
}
} else if (clickEvent.target.id === "label-router-peers") {
2020-11-10 21:48:08 -05:00
if (document.getElementById("label-peers-list").style.display !== "none") {
2020-09-09 23:23:02 -04:00
console.log("hiding label-peers-list");
2020-11-10 21:48:08 -05:00
document.getElementById("label-peers-list").style.display = "none";
} else {
2020-09-09 23:23:02 -04:00
console.log("showing label-peers-list");
2020-11-10 21:48:08 -05:00
document.getElementById("label-peers-list").style.display = "block";
2020-09-09 23:23:02 -04:00
}
} else if (clickEvent.target.id === "label-router-bandwidth") {
2020-11-10 21:48:08 -05:00
if (
document.getElementById("label-bandwidth-list").style.display !== "none"
) {
2020-09-09 23:23:02 -04:00
console.log("hiding label-bandwidth-list");
2020-11-10 21:48:08 -05:00
document.getElementById("label-bandwidth-list").style.display = "none";
} else {
2020-09-09 23:23:02 -04:00
console.log("showing label-bandwidth-list");
2020-11-10 21:48:08 -05:00
document.getElementById("label-bandwidth-list").style.display = "block";
2020-09-09 23:23:02 -04:00
}
2020-01-11 22:01:37 -05:00
} else if (clickEvent.target.id === "search-submit") {
console.log("attempting to create search tab");
goSearch();
2020-01-14 17:46:26 -05:00
} else if (clickEvent.target.id === "browser-action") {
console.log("showing a browser action");
showBrowsing();
} else if (clickEvent.target.id === "torrent-action") {
console.log("showing a torrent action");
showTorrentsMenu();
} else if (clickEvent.target.id === "window-preface-title") {
console.log("attempting to create homepage tab");
goHome();
2020-01-11 22:32:25 -05:00
} else if (clickEvent.target.id === "window-visit-index") {
2020-01-12 18:01:25 -05:00
console.log("attempting to create index tab");
2020-01-11 22:32:25 -05:00
goIndex();
} else if (clickEvent.target.id === "window-visit-homepage") {
2019-11-22 17:55:58 -05:00
console.log("attempting to create homepage tab");
goHome();
2020-01-12 18:01:25 -05:00
} else if (clickEvent.target.id === "window-visit-toopie") {
console.log("attempting to create toopie tab");
goToopie();
} else if (clickEvent.target.id === "window-visit-i2ptunnel") {
2019-11-22 17:55:58 -05:00
console.log("attempting to create i2ptunnel tab");
goTunnel();
} else if (clickEvent.target.id === "window-visit-susimail") {
2019-11-22 17:55:58 -05:00
console.log("attempting to create susimail tab");
goMail();
} else if (clickEvent.target.id === "window-visit-snark") {
2019-11-22 17:55:58 -05:00
console.log("attempting to create snark tab");
goSnark();
} else if (clickEvent.target.id === "clear-browser-data") {
2019-10-06 15:18:10 -04:00
forgetBrowsingData();
} else if (clickEvent.target.id === "check-i2p-control") {
//echo("I2P Router Detected", "panel-section-i2pcontrol-check");
} else if (clickEvent.target.id === "enable-web-rtc") {
if (clickEvent.target.checked) {
2019-12-24 16:51:38 -05:00
browser.runtime.sendMessage({ rtc: "enableWebRTC" });
} else {
2019-12-24 16:51:38 -05:00
browser.runtime.sendMessage({ rtc: "disableWebRTC" });
2019-10-28 01:11:16 -04:00
}
checkPeerConnection();
return;
} else if (clickEvent.target.id === "disable-history") {
if (clickEvent.target.checked) {
2019-12-24 16:51:38 -05:00
browser.runtime.sendMessage({ history: "disableHistory" });
} else {
2019-12-24 16:51:38 -05:00
browser.runtime.sendMessage({ history: "enableHistory" });
}
return;
}
2019-03-13 17:50:51 -04:00
clickEvent.preventDefault();
2019-10-06 15:18:10 -04:00
});
2019-11-10 22:24:10 -05:00
2020-11-10 21:48:08 -05:00
window.onload = function (e) {
if (document.getElementById("label-peers-list") != null) {
2020-11-10 21:48:08 -05:00
document.getElementById("label-peers-list").style.display = "none";
}
if (document.getElementById("label-bandwidth-list") != null) {
2020-11-10 21:48:08 -05:00
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);
}
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() {
console.log("Help tab created");
}
function gotProxyInfo(info) {
let port = info.value.http.split(":")[1];
if (port == "7644") {
let createRhizomeData = {
2020-11-10 21:48:08 -05:00
url: "about:I2p",
};
console.log("visiting homepage");
let creating = browser.tabs.create(createRhizomeData);
creating.then(onTabCreated, onTabError);
} else {
let createData = {
2020-11-10 21:48:08 -05:00
url: "home.html",
};
console.log("visiting homepage");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
}
console.log("(bookmarks) adding home page bookmark");
}
console.log("(bookmarks) checking if we're running in an I2P Browser");
var gettingProxyInfo = browser.proxy.settings.get({});
gettingProxyInfo.then(gotProxyInfo);
}
2020-01-11 22:32:25 -05:00
function goIndex() {
function onTabError() {
console.log("Help tab created");
}
let createData = {
2020-11-10 21:48:08 -05:00
url: "index.html",
2020-01-11 22:32:25 -05:00
};
console.log("visiting help");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2020-01-11 22:32:25 -05:00
}
2020-01-12 18:01:25 -05:00
function goToopie() {
function onTabError() {
console.log("Toopie tab created");
}
console.log("visiting toopie");
let creating = browser.sidebarAction.open();
creating.then(onTabCreated, onTabError);
2020-01-12 18:01:25 -05:00
}
function onTabCreated() {
console.log("Tab Created");
2019-11-22 17:49:27 -05:00
}
2020-01-11 22:01:37 -05:00
function goSearch() {
function onTabError() {
console.log("Search tab created");
}
let createData = {
url:
"http://yacy.idk.i2p/yacysearch.html?" +
2020-01-11 22:01:37 -05:00
"query=" +
2020-11-10 21:48:08 -05:00
document.getElementById("search-query").value,
2020-01-11 22:01:37 -05:00
};
console.log("visiting legwork");
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2020-01-11 22:01:37 -05:00
}
function routerAddr() {
if (!control_host) var control_host = "127.0.0.1";
if (!control_port) var control_port = "7657";
return control_host + ":" + control_port;
}
2019-11-22 17:49:27 -05:00
function goTunnel() {
function onTabError() {
console.log("I2PTunnel tab created");
}
2019-11-22 17:49:27 -05:00
let createData = {
2020-11-10 21:48:08 -05:00
url: "http://" + routerAddr() + "/i2ptunnel",
2019-11-22 17:49:27 -05:00
};
console.log("visiting i2ptunnel");
2019-11-22 17:49:27 -05:00
let creating = browser.tabs.create(createData);
creating.then(onTabCreated, onTabError);
2019-11-22 17:49:27 -05:00
}
function goMail() {
function onTabError() {
console.log("Mail tab created");
}
2019-11-22 17:49:27 -05:00
let createData = {
2020-11-10 21:48:08 -05:00
url: "http://" + routerAddr() + "/susimail",
2019-11-22 17:49:27 -05:00
};
console.log("visiting mail");
2019-11-22 17:49:27 -05:00
let creating = browser.tabs.create(createData);
creating(onTabCreated, onTabError);
2019-11-22 17:49:27 -05:00
}
function goSnark() {
function onTabError() {
console.log("Snark tab created");
}
2019-11-22 17:49:27 -05:00
let createData = {
2020-11-10 21:48:08 -05:00
url: "http://" + routerAddr() + "/i2psnark",
2019-11-22 17:49:27 -05:00
};
console.log("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) {
console.log(" was not removed");
} else {
console.log(" was removed");
}
}
2019-11-10 22:24:10 -05:00
function onRemoved() {
var searching = browser.history.search({
text: historyItem.url,
2020-11-10 21:48:08 -05:00
startTime: 0,
});
searching.then(onCleaned);
}
if (!history) {
2019-12-24 11:21:07 -05:00
if (i2pHost(historyItem.url)) {
2019-12-24 16:51:38 -05:00
var deletingUrl = browser.history.deleteUrl(historyItem.url);
}
deletingUrl.then(onRemoved);
}
2019-11-10 22:24:10 -05:00
}
2020-01-22 21:18:11 -05:00
if (UpdateContents !== undefined) UpdateContents();
const minutes = 0.2;
const interval = minutes * 60 * 1000;
2020-11-10 21:48:08 -05:00
setInterval(function () {
2020-01-22 21:18:11 -05:00
if (UpdateContents !== undefined) UpdateContents();
}, interval);
2020-12-03 13:17:06 -05:00
fetch("http://127.0.0.1:7669").then((myJson) => {
if (myJson.status == 200) {
let irc = document.getElementById("visit-irc");
if (irc != null) {
irc.classList.remove("hidden");
}
}
});