diff --git a/cert.js b/cert.js index 6040b29..ce4ec76 100644 --- a/cert.js +++ b/cert.js @@ -1,52 +1,45 @@ -function blankContent(id) { - let infoTitle = document.getElementById(id); - if (infoTitle === null) { - console.log("content error", id); +function clearContent(titleId) { + const titleElement = document.getElementById(titleId); + if (!titleElement) { return; } - infoTitle.textContent = ""; + titleElement.textContent = ""; } -function contentUpdateById(id, message) { - let infoTitle = document.getElementById(id); - let messageContent = chrome.i18n.getMessage(message); - if (infoTitle === null) { - console.log("content error", id, messageContent); - return; - } - infoTitle.textContent = messageContent; +function updateContentById(id, message) { + const element = document.getElementById(id); + if (!element) return; + const content = chrome.i18n.getMessage(message); + if (!content) return; + element.textContent = content; } -contentUpdateById("TypeLabel", "siteLabel"); +updateContentById("TypeLabel", "siteLabel"); -contentUpdateById("CertLabel", "CertLabel"); +updateContentById("CertLabel", "CertLabel"); -function tabCheck(tabInfo) { - // Information Section - console.log("(cert) checking tab"); - var host = tabInfo[0].url.split(".i2p")[0] + ".i2p"; +function checkTab(tabInfo) { + const url = tabInfo[0].url; + const host = url.split(".i2p")[0] + ".i2p"; if (host.length < 51) { - contentUpdateById("AddressInfo", "isHostName"); - } else { - if (host.endsWith("b32.i2p")) { - contentUpdateById("AddressInfo", "isBase32"); - } + updateContentById("AddressInfo", "isHostName"); + } else if (host.endsWith("b32.i2p")) { + updateContentById("AddressInfo", "isBase32"); } - if (host.startsWith("https")) { - contentUpdateById("AddressCertInfo", "certPresent"); - console.log("(cert) initiating request to check server cert"); + if (url.startsWith("https")) { + updateContentById("AddressCertInfo", "certPresent"); fetch(host).then((response) => { console.log("Updating cert information", response); }); } else { - contentUpdateById("AddressCertInfo", "certAbsent"); - blankContent("SignedLabel"); + updateContentById("AddressCertInfo", "certAbsent"); + clearContent("SignedLabel"); } } function tabError(error) { - console.log(`Error: ${error}`); + console.error(`Error: ${error}`); } const gettingCurrent = browser.tabs.query({ active: true }); -gettingCurrent.then(tabCheck, tabError); +gettingCurrent.then(checkTab, tabError); diff --git a/consoleinfo.js b/consoleinfo.js index 47a61c9..7c43676 100644 --- a/consoleinfo.js +++ b/consoleinfo.js @@ -1,65 +1,44 @@ -document.addEventListener( - "DOMContentLoaded", - function () { - fetch("http://127.0.0.1:7657/welcome").then( - (myJson) => { - console.warn("(consoleinfo)", myJson); - contentUpdateById("router-check", "consoleSuccessStatus"); - let routerness = document.querySelectorAll(".routerness"); - if (routerness !== null) { - unhide(routerness); - } - }, - (error) => { - console.error("(consoleinfo)", error); - contentUpdateById("router-check", "consoleFailedStatus"); - let routerness = document.querySelectorAll(".routerness"); - if (routerness !== null) { - hide(routerness); - } - } - ); - }, - false -); +document.addEventListener("DOMContentLoaded", consoleStatus, false); -function hide(elements) { - elements = elements.length ? elements : [elements]; - for (var index = 0; index < elements.length; index++) { - if (elements[index].style !== undefined) { - elements[index].style.display = "none"; - } +function consoleStatus() { + let recv = fetch("http://127.0.0.1:7657/welcome"); + recv.then(routerConsoleSuccess, routerConsoleError); +} + +function routerConsoleSuccess(myJson) { + console.warn("(consoleinfo)", myJson); + contentUpdateById("router-check", "consoleSuccessStatus"); + let routerness = document.querySelectorAll(".routerness"); + if (routerness !== null) { + unhide(routerness); } } -function unhide(elements) { - elements = elements.length ? elements : [elements]; - for (var index = 0; index < elements.length; index++) { - if (elements[index].style !== undefined) { - elements[index].style.display = "inline-block"; - } +function routerConsoleError(error) { + console.error("(consoleinfo)", error); + contentUpdateById("router-check", "consoleFailedStatus"); + let routerness = document.querySelectorAll(".routerness"); + if (routerness !== null) { + hide(routerness); } } -//TODO: Don't hard-code this. -/* -fetch("http://127.0.0.1:7657/themes/console/light/images/i2plogo.png") - .then((myJson) => { - var consoleLinks = document.querySelectorAll(".application-info"); - unhide(consoleLinks); - }) - .catch((error) => { - var consoleLinks = document.querySelectorAll(".application-info"); - hide(consoleLinks); +function hide(elementsToHide) { + const elements = Array.isArray(elementsToHide) + ? elementsToHide + : [elementsToHide]; + elements.forEach((element) => { + element.style.display = "none"; }); +} -fetch("http://127.0.0.1:7657/jsonrpc/") - .then((myJson) => { - var toopieLinks = document.querySelectorAll(".window-visit-toopie"); - unhide(toopieLinks); - }) - .catch((error) => { - var toopieLinks = document.querySelectorAll(".window-visit-toopie"); - hide(toopieLinks); +function unhide(elementsToShow) { + const elements = Array.isArray(elementsToShow) + ? elementsToShow + : [elementsToShow]; + elements.forEach((element) => { + if (element.style) { + element.style.display = "inline-block"; + } }); -*/ +} diff --git a/host.js b/host.js index 7b8042d..f13453b 100644 --- a/host.js +++ b/host.js @@ -1,4 +1,5 @@ function isProxyHost(requestDetails) { + if (requestDetails.url.includes("jsonrpc")) return false; const originUrl = requestDetails.originUrl; const isWindowOrHomeUrl = originUrl !== browser.runtime.getURL("window.html") && @@ -7,14 +8,14 @@ function isProxyHost(requestDetails) { if (isWindowOrHomeUrl) { return false; } - - const urlParts = requestDetails.url.split("/"); - const hostname = urlParts[2].indexOf("://") > -1 ? urlParts[2] : urlParts[0]; - + let rurl = new URL(requestDetails.url); + let hostname = rurl.hostname; + console.log("(proxy) proxyinfo proxy.i2p check", hostname); if ( hostname === "proxy.i2p" || hostname === "c6lilt4cr5x7jifxridpkesf2zgfwqfchtp6laihr4pdqomq25iq.b32.i2p" ) { + console.log("(proxy) proxyinfo proxy.i2p positive", hostname); return true; } diff --git a/proxy.js b/proxy.js index 6823985..6db597c 100644 --- a/proxy.js +++ b/proxy.js @@ -30,13 +30,14 @@ function shouldProxyRequest(requestInfo) { } var handleContextProxyRequest = async function (requestDetails) { + console.log("(proxy) proxyinfo request Details", requestDetails.url); if (isProxyHost(requestDetails)) { proxy = { type: proxy_scheme(), host: proxy_host(), port: proxy_port(), }; - console.warn("(proxy) is proxy check"); + console.warn("(proxy) is proxyinfo proxy.i2p check"); return proxy; } diff --git a/proxyinfo.js b/proxyinfo.js index 353be0d..0fdd7b6 100644 --- a/proxyinfo.js +++ b/proxyinfo.js @@ -1,48 +1,51 @@ -document.addEventListener( - "DOMContentLoaded", - function () { - fetch("http://proxy.i2p", { cache: "no-store" }).then( - (myJson) => { - console.warn("(proxyinfo)", myJson); - contentUpdateById("proxy-check", "proxySuccessStatus"); - let readyness = document.querySelectorAll(".readyness"); - if (readyness !== null) { - unhide(readyness); - } - }, - (error) => { - console.error("(proxyinfo)", error); - contentUpdateById("proxy-check", "proxyFailedStatus"); - let readyness = document.querySelectorAll(".readyness"); - if (readyness !== null) { - hide(readyness); - } - } - ); - }, - false -); +document.addEventListener("DOMContentLoaded", proxyStatus, false); + +function proxyStatus() { + console.log("(proxyinfo) checking proxy status"); + fetch("http://proxy.i2p", { cache: "no-store" }).then( + proxyStatusSuccess, + proxyStatusError + ); +} + +function proxyStatusSuccess(myJson) { + console.warn("(proxyinfo)", myJson); + contentUpdateById("proxy-check", "proxySuccessStatus"); + let readyness = document.querySelectorAll(".readyness"); + if (readyness !== null) { + unhide(readyness); + } +} + +function proxyStatusError(error) { + console.error("(proxyinfo)", error); + contentUpdateById("proxy-check", "proxyFailedStatus"); + let readyness = document.querySelectorAll(".readyness"); + if (readyness !== null) { + hide(readyness); + } +} function hide(elements) { - elements = elements.length ? elements : [elements]; - for (var index = 0; index < elements.length; index++) { - if (elements[index].style !== undefined) { - elements[index].style.display = "none"; + const elems = Array.isArray(elements) ? elements : [elements]; + elems.forEach((elem) => { + if (elem.style) { + elem.style.display = "none"; } - } + }); } function unhide(elements) { - elements = elements.length ? elements : [elements]; - for (var index = 0; index < elements.length; index++) { - if (elements[index].style !== undefined) { - elements[index].style.display = "inline-block"; + const elems = Array.isArray(elements) ? elements : [elements]; + elems.forEach((elem) => { + if (elem.style) { + elem.style.display = "inline-block"; } - } + }); } //TODO: Don't hard-code this. -fetch("http://127.0.0.1:7657/themes/console/light/images/i2plogo.png") +/*fetch("http://127.0.0.1:7657/themes/console/light/images/i2plogo.png") .then((myJson) => { var consoleLinks = document.querySelectorAll(".application-info"); unhide(consoleLinks); @@ -61,3 +64,4 @@ fetch("http://127.0.0.1:7657/jsonrpc/") var toopieLinks = document.querySelectorAll(".window-visit-toopie"); hide(toopieLinks); }); +*/