feat: add built-in Moon I2P start page to Firefox and Android
- Firefox extension: add start.html/css/js as homepage and new-tab page (manifest bumped to 0.1.5, .xpi rebuilt). Shows router readiness, tunnel/NetDB/DHT tiles, torrents, and a .i2p/magnet address bar. - openManager message now accepts an optional hash and reuses any open manager tab. - Android: default page is file:///android_asset/start.html, backed by a MoonI2pStart JS bridge (status, torrents, open URL, diagnostics, copy .b32). Blocks file: navigation from the WebView. - RouterService: add fetchLocalApiJsonOrNull for bounded local API reads. - Built-in .i2p destinations reordered (NotBob, Postman first); README updated to match.
This commit is contained in:
1 parent
9d3df6e100
commit
7139a64544
11 files changed
+1355
-37
No files matched your search
@@ -416,12 +416,14 @@ browser.runtime.onMessage.addListener(async (msg) => {
|
||||
10000
|
||||
);
|
||||
case "openManager": {
|
||||
const url = browser.runtime.getURL("manager.html");
|
||||
const existing = await browser.tabs.query({ url });
|
||||
const baseUrl = browser.runtime.getURL("manager.html");
|
||||
const hash = typeof msg.hash === "string" && msg.hash ? msg.hash : "";
|
||||
const targetUrl = hash ? `${baseUrl}${hash}` : baseUrl;
|
||||
const existing = await browser.tabs.query({ url: `${baseUrl}*` });
|
||||
if (existing.length > 0) {
|
||||
await browser.tabs.update(existing[0].id, { active: true });
|
||||
await browser.tabs.update(existing[0].id, { active: true, url: targetUrl });
|
||||
} else {
|
||||
await browser.tabs.create({ url });
|
||||
await browser.tabs.create({ url: targetUrl });
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Moon I2P Torrent & Proxy",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"description": "Route .i2p browsing through moon-i2p and manage I2P BitTorrent + I2P DHT torrents from Firefox.",
|
||||
"icons": {
|
||||
"48": "icon.svg",
|
||||
@@ -13,6 +13,12 @@
|
||||
"strict_min_version": "109.0"
|
||||
}
|
||||
},
|
||||
"chrome_settings_overrides": {
|
||||
"homepage": "start.html"
|
||||
},
|
||||
"chrome_url_overrides": {
|
||||
"newtab": "start.html"
|
||||
},
|
||||
"permissions": [
|
||||
"proxy",
|
||||
"storage",
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
body.start-page {
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
padding: 28px 18px 40px;
|
||||
background:
|
||||
radial-gradient(900px 420px at 50% -80px, rgba(109, 93, 252, 0.2), transparent 70%),
|
||||
radial-gradient(640px 320px at 85% 0%, rgba(20, 184, 166, 0.12), transparent 65%),
|
||||
var(--bg);
|
||||
}
|
||||
|
||||
.start-wrap {
|
||||
max-width: 920px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.start-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.brand-sub {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.pill.booting {
|
||||
background: rgba(245, 158, 11, 0.18);
|
||||
color: #fcd34d;
|
||||
}
|
||||
|
||||
.warmup-banner {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 12px 14px;
|
||||
margin-bottom: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.warmup-banner.is-booting {
|
||||
border-color: rgba(245, 158, 11, 0.55);
|
||||
background: linear-gradient(90deg, rgba(245, 158, 11, 0.1), var(--card) 55%);
|
||||
}
|
||||
|
||||
.warmup-banner.is-ready {
|
||||
border-color: rgba(20, 184, 166, 0.45);
|
||||
background: linear-gradient(90deg, rgba(20, 184, 166, 0.1), var(--card) 55%);
|
||||
}
|
||||
|
||||
.warmup-banner.is-offline {
|
||||
border-color: rgba(239, 68, 68, 0.45);
|
||||
}
|
||||
|
||||
.warmup-title {
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.warmup-detail {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.nav-card {
|
||||
padding: 14px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.nav-form {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-form input[type="text"] {
|
||||
padding: 10px 12px;
|
||||
font-size: 14px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.nav-form button {
|
||||
padding: 10px 18px;
|
||||
font-size: 14px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.telemetry-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.tile {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 11px 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.tile-btn {
|
||||
width: 100%;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s ease, transform 0.15s ease;
|
||||
}
|
||||
|
||||
.tile-btn:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.tile-sub {
|
||||
margin-top: 3px;
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.action-strip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.section-heading {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--muted);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sites-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.site-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 12px 14px;
|
||||
color: var(--text);
|
||||
text-decoration: none;
|
||||
transition: border-color 0.15s ease, background 0.15s ease;
|
||||
}
|
||||
|
||||
.site-card:hover,
|
||||
.site-card:focus-visible {
|
||||
border-color: var(--accent);
|
||||
background: #17213a;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.site-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.site-title {
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.tag-pill {
|
||||
display: inline-block;
|
||||
padding: 2px 7px;
|
||||
border-radius: 999px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
background: rgba(109, 93, 252, 0.18);
|
||||
color: #c4b5fd;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.site-host {
|
||||
color: #5eead4;
|
||||
}
|
||||
|
||||
.site-desc {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.start-footer {
|
||||
margin-top: 16px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--border);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.b32-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.b32-text {
|
||||
max-width: 420px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.telemetry-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 460px) {
|
||||
.nav-form {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Moon I2P Start Page</title>
|
||||
<link rel="stylesheet" href="ui.css" />
|
||||
<link rel="stylesheet" href="start.css" />
|
||||
</head>
|
||||
<body class="start-page">
|
||||
<main class="start-wrap">
|
||||
<header class="start-header">
|
||||
<div class="brand">
|
||||
<img src="icon.svg" alt="" />
|
||||
<div>
|
||||
<div>Moon I2P</div>
|
||||
<div class="brand-sub">Private .i2p Browser & BitTorrent/DHT Router</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span id="status-pill" class="pill offline">Checking...</span>
|
||||
<button id="start-router-btn" type="button" style="display:none;">Start Router</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="warmup-banner" class="warmup-banner">
|
||||
<div>
|
||||
<div id="warmup-title" class="warmup-title">Connecting to bundled moon-i2p router...</div>
|
||||
<div id="warmup-detail" class="warmup-detail">
|
||||
Checking tunnel pool and NetDB readiness. .i2p browsing works automatically once tunnels are up.
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card nav-card">
|
||||
<form id="nav-form" class="nav-form">
|
||||
<input
|
||||
id="nav-input"
|
||||
type="text"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
autofocus
|
||||
placeholder="Enter .i2p domain (e.g. notbob.i2p), .b32.i2p address, or magnet: link..."
|
||||
/>
|
||||
<button type="submit">Go</button>
|
||||
</form>
|
||||
<div id="nav-msg" class="msg"></div>
|
||||
</section>
|
||||
|
||||
<section class="telemetry-grid" aria-label="Router Telemetry">
|
||||
<div class="tile">
|
||||
<div class="stat-label">Tunnels</div>
|
||||
<div id="tile-tunnels-val" class="stat-val">--</div>
|
||||
<div id="tile-tunnels-sub" class="tile-sub">Waiting for router</div>
|
||||
</div>
|
||||
<div class="tile">
|
||||
<div class="stat-label">NetDB Peers</div>
|
||||
<div id="tile-netdb-val" class="stat-val">--</div>
|
||||
<div id="tile-netdb-sub" class="tile-sub">-- floodfills</div>
|
||||
</div>
|
||||
<div class="tile">
|
||||
<div class="stat-label">I2P DHT</div>
|
||||
<div id="tile-dht-val" class="stat-val">--</div>
|
||||
<div id="tile-dht-sub" class="tile-sub">Proto 17 / 18</div>
|
||||
</div>
|
||||
<button id="torrents-tile" class="tile tile-btn" type="button">
|
||||
<div class="stat-label">Torrents</div>
|
||||
<div id="tile-torrents-val" class="stat-val">0 active</div>
|
||||
<div id="tile-torrents-sub" class="tile-sub">Open manager</div>
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="action-strip">
|
||||
<div class="action-buttons">
|
||||
<button id="open-manager-btn" type="button">Torrents & DHT Manager</button>
|
||||
<button id="open-diag-btn" class="secondary" type="button">Diagnostics & Logs</button>
|
||||
</div>
|
||||
<span id="proxy-pill" class="pill">Proxy: 127.0.0.1:4444</span>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 class="section-heading">
|
||||
<span>Built-in .i2p Destinations</span>
|
||||
<span>Zero-lookup aliases ready</span>
|
||||
</h2>
|
||||
<div class="sites-grid">
|
||||
<a class="site-card" href="http://notbob.i2p/">
|
||||
<div class="site-top">
|
||||
<span class="site-title">NotBob Directory</span>
|
||||
<span class="tag-pill">Directory</span>
|
||||
</div>
|
||||
<div class="site-host mono">notbob.i2p</div>
|
||||
<div class="site-desc">Uptime-monitored directory of live .i2p eepsites</div>
|
||||
</a>
|
||||
|
||||
<a class="site-card" href="http://tracker2.postman.i2p/">
|
||||
<div class="site-top">
|
||||
<span class="site-title">Postman Tracker</span>
|
||||
<span class="tag-pill">Torrents</span>
|
||||
</div>
|
||||
<div class="site-host mono">tracker2.postman.i2p</div>
|
||||
<div class="site-desc">Public I2P BitTorrent tracker & torrent index</div>
|
||||
</a>
|
||||
|
||||
<a class="site-card" href="http://insulaocculta.i2p/">
|
||||
<div class="site-top">
|
||||
<span class="site-title">Insula Occulta</span>
|
||||
<span class="tag-pill">Torrents</span>
|
||||
</div>
|
||||
<div class="site-host mono">insulaocculta.i2p</div>
|
||||
<div class="site-desc">I2P music & media torrent tracker</div>
|
||||
</a>
|
||||
|
||||
<a class="site-card" href="http://stats.i2p/">
|
||||
<div class="site-top">
|
||||
<span class="site-title">I2P Stats</span>
|
||||
<span class="tag-pill">Network</span>
|
||||
</div>
|
||||
<div class="site-host mono">stats.i2p</div>
|
||||
<div class="site-desc">Network health, router stats & hosts.txt addressbook</div>
|
||||
</a>
|
||||
|
||||
<a class="site-card" href="http://zzz.i2p/">
|
||||
<div class="site-top">
|
||||
<span class="site-title">zzz.i2p</span>
|
||||
<span class="tag-pill">Community</span>
|
||||
</div>
|
||||
<div class="site-host mono">zzz.i2p</div>
|
||||
<div class="site-desc">I2P developer forums & protocol proposals</div>
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="active-torrents-card" class="card" style="display:none;">
|
||||
<h2>
|
||||
<span>Active Torrents (<span id="active-torrents-count">0</span>)</span>
|
||||
<button id="open-manager-btn-2" class="secondary" type="button">Open Manager</button>
|
||||
</h2>
|
||||
<div id="active-torrents-list"></div>
|
||||
</section>
|
||||
|
||||
<footer class="start-footer">
|
||||
<div id="footer-proxy" class="mono">Proxy: 127.0.0.1:4444</div>
|
||||
<div class="b32-wrap">
|
||||
<span class="stat-label">Torrent .b32.i2p:</span>
|
||||
<span id="footer-b32" class="mono b32-text" title="--">--</span>
|
||||
<button id="copy-b32-btn" class="secondary" type="button">Copy .b32</button>
|
||||
</div>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
<script src="start.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,281 @@
|
||||
"use strict";
|
||||
|
||||
function normalizeNavigationInput(raw) {
|
||||
const trimmed = String(raw || "").trim();
|
||||
if (!trimmed) {
|
||||
return { kind: "empty" };
|
||||
}
|
||||
if (/^magnet:/i.test(trimmed)) {
|
||||
return { kind: "magnet", value: trimmed };
|
||||
}
|
||||
if (/\s/.test(trimmed)) {
|
||||
return {
|
||||
kind: "invalid",
|
||||
error: "Enter a .i2p domain (e.g. notbob.i2p), .b32.i2p address, or magnet: link.",
|
||||
};
|
||||
}
|
||||
if (/^https?:\/\//i.test(trimmed)) {
|
||||
return { kind: "url", value: trimmed };
|
||||
}
|
||||
if (!/[./:]/.test(trimmed)) {
|
||||
return { kind: "url", value: "http://" + trimmed + ".i2p/" };
|
||||
}
|
||||
return { kind: "url", value: "http://" + trimmed };
|
||||
}
|
||||
|
||||
if (typeof module !== "undefined" && module.exports) {
|
||||
module.exports = { normalizeNavigationInput };
|
||||
}
|
||||
|
||||
if (typeof document !== "undefined" && typeof browser !== "undefined") {
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
function fmtBytes(n) {
|
||||
if (!n || n <= 0) return "0 B";
|
||||
const units = ["B", "KiB", "MiB", "GiB"];
|
||||
let u = 0;
|
||||
let v = n;
|
||||
while (v >= 1024 && u < units.length - 1) {
|
||||
v /= 1024;
|
||||
u++;
|
||||
}
|
||||
return `${v.toFixed(u === 0 ? 0 : 1)} ${units[u]}`;
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
return String(s || "").replace(/[&<>"']/g, (c) => ({
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
})[c]);
|
||||
}
|
||||
|
||||
function setNavMsg(text, isErr = false) {
|
||||
const el = $("nav-msg");
|
||||
if (!el) return;
|
||||
el.textContent = text;
|
||||
el.className = isErr ? "msg err" : "msg";
|
||||
}
|
||||
|
||||
async function copyTextToClipboard(text) {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch (_e) {
|
||||
// Fall through to textarea + execCommand fallback
|
||||
}
|
||||
}
|
||||
const ta = document.createElement("textarea");
|
||||
ta.value = text;
|
||||
ta.setAttribute("readonly", "");
|
||||
ta.style.position = "fixed";
|
||||
ta.style.top = "-9999px";
|
||||
ta.style.left = "-9999px";
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
let ok = false;
|
||||
try {
|
||||
ok = document.execCommand("copy");
|
||||
} finally {
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
let currentB32 = "";
|
||||
let copyTimer = null;
|
||||
let refreshInFlight = false;
|
||||
|
||||
async function refreshStatus() {
|
||||
if (refreshInFlight || document.hidden) return;
|
||||
refreshInFlight = true;
|
||||
try {
|
||||
const st = await browser.runtime.sendMessage({ type: "getState" });
|
||||
if (!st) return;
|
||||
|
||||
const cfg = st.settings || {};
|
||||
const rs = st.routerStatus || {};
|
||||
const torrents = Array.isArray(st.torrents) ? st.torrents : [];
|
||||
const dhtNodes = (st.dht && Array.isArray(st.dht.nodes) ? st.dht.nodes.length : 0);
|
||||
|
||||
const proxyAddr = `${cfg.proxyHost || "127.0.0.1"}:${cfg.proxyPort || 4444}`;
|
||||
const proxyEnabled = cfg.proxyEnabled !== false;
|
||||
$("proxy-pill").textContent = proxyEnabled ? `Proxy: ${proxyAddr}` : `Proxy Disabled (${proxyAddr})`;
|
||||
$("proxy-pill").className = proxyEnabled ? "pill online" : "pill offline";
|
||||
$("footer-proxy").textContent = `Proxy: ${proxyAddr} (${proxyEnabled ? "enabled" : "disabled"})`;
|
||||
|
||||
const pill = $("status-pill");
|
||||
const startBtn = $("start-router-btn");
|
||||
const banner = $("warmup-banner");
|
||||
const bannerTitle = $("warmup-title");
|
||||
const bannerDetail = $("warmup-detail");
|
||||
|
||||
if (!rs.ok) {
|
||||
pill.textContent = "Offline";
|
||||
pill.className = "pill offline";
|
||||
startBtn.style.display = "";
|
||||
banner.className = "warmup-banner is-offline";
|
||||
bannerTitle.textContent = "moon-i2p router is offline or starting";
|
||||
bannerDetail.textContent = "Click Start Router above or wait for the bundled router to finish launching.";
|
||||
|
||||
$("tile-tunnels-val").textContent = "--";
|
||||
$("tile-tunnels-sub").textContent = "Router unreachable";
|
||||
$("tile-netdb-val").textContent = "--";
|
||||
$("tile-netdb-sub").textContent = "-- floodfills";
|
||||
$("tile-dht-val").textContent = "--";
|
||||
$("tile-dht-sub").textContent = "Proto 17 / 18";
|
||||
currentB32 = "";
|
||||
$("footer-b32").textContent = "--";
|
||||
$("footer-b32").title = "--";
|
||||
} else {
|
||||
startBtn.style.display = "none";
|
||||
const inTunnels = Number(rs.inbound_tunnels || 0);
|
||||
const outTunnels = Number(rs.outbound_tunnels || 0);
|
||||
const routers = Number(rs.netdb_routers || 0);
|
||||
const floodfills = Number(rs.netdb_floodfills || 0);
|
||||
const dhtInfo = rs.dht || {};
|
||||
const dhtCount = Number(dhtInfo.routing_table_nodes ?? dhtNodes ?? 0);
|
||||
|
||||
$("tile-tunnels-val").textContent = `${inTunnels}in / ${outTunnels}out`;
|
||||
$("tile-tunnels-sub").textContent = inTunnels > 0 && outTunnels > 0 ? "Tunnels established" : "Building client tunnels";
|
||||
$("tile-netdb-val").textContent = `${routers}`;
|
||||
$("tile-netdb-sub").textContent = `${floodfills} floodfills`;
|
||||
$("tile-dht-val").textContent = `${dhtCount} nodes`;
|
||||
$("tile-dht-sub").textContent = `${dhtInfo.queries_sent || 0} sent / ${dhtInfo.peers_discovered || 0} peers`;
|
||||
|
||||
currentB32 = rs.torrent_b32 || "";
|
||||
$("footer-b32").textContent = currentB32 || "--";
|
||||
$("footer-b32").title = currentB32 || "--";
|
||||
|
||||
if (inTunnels === 0 || outTunnels === 0) {
|
||||
pill.textContent = "Bootstrapping...";
|
||||
pill.className = "pill booting";
|
||||
banner.className = "warmup-banner is-booting";
|
||||
bannerTitle.textContent = "Bootstrapping I2P tunnels (typically 15–30s)...";
|
||||
bannerDetail.textContent = `NetDB has ${routers} peers (${floodfills} floodfills), ${inTunnels}in/${outTunnels}out tunnels built. .i2p sites will load once tunnels come up.`;
|
||||
} else {
|
||||
pill.textContent = rs.public_mode ? "Public Online" : "I2P Ready";
|
||||
pill.className = "pill online";
|
||||
banner.className = "warmup-banner is-ready";
|
||||
bannerTitle.textContent = "I2P tunnels active and ready";
|
||||
bannerDetail.textContent = `${inTunnels} inbound / ${outTunnels} outbound tunnels · ${routers} NetDB peers · Ready to browse .i2p and download torrents.`;
|
||||
}
|
||||
}
|
||||
|
||||
const activeCount = torrents.filter((t) => !t.completed && !t.paused).length;
|
||||
$("tile-torrents-val").textContent = `${torrents.length} total`;
|
||||
$("tile-torrents-sub").textContent = activeCount > 0 ? `${activeCount} downloading · Open manager` : "Open manager";
|
||||
|
||||
const tCard = $("active-torrents-card");
|
||||
const tList = $("active-torrents-list");
|
||||
$("active-torrents-count").textContent = String(torrents.length);
|
||||
if (torrents.length === 0) {
|
||||
tCard.style.display = "none";
|
||||
tList.innerHTML = "";
|
||||
} else {
|
||||
tCard.style.display = "";
|
||||
tList.innerHTML = torrents
|
||||
.slice(0, 6)
|
||||
.map((t) => {
|
||||
const pct = Math.max(0, Math.min(100, Number(t.progress_pct || 0)));
|
||||
return `
|
||||
<div class="torrent-item">
|
||||
<div class="row" style="justify-content:space-between;">
|
||||
<strong>${escapeHtml(t.name)}</strong>
|
||||
<span class="pill ${t.completed ? "online" : ""}">${escapeHtml(t.state)} · ${pct}%</span>
|
||||
</div>
|
||||
<div class="progress-track"><div class="progress-fill" style="width:${pct}%"></div></div>
|
||||
<div style="color:var(--muted);font-size:11px;">
|
||||
${fmtBytes(t.downloaded_bytes)} / ${fmtBytes(t.total_length)} · ${t.connected_peers || 0}/${t.known_peers || 0} peers
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
} catch (_e) {
|
||||
// Ignore transient polling errors while background wakes up
|
||||
} finally {
|
||||
refreshInFlight = false;
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
$("nav-form").addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const parsed = normalizeNavigationInput($("nav-input").value);
|
||||
if (parsed.kind === "empty") {
|
||||
setNavMsg("");
|
||||
return;
|
||||
}
|
||||
if (parsed.kind === "invalid") {
|
||||
setNavMsg(parsed.error, true);
|
||||
return;
|
||||
}
|
||||
if (parsed.kind === "magnet") {
|
||||
setNavMsg("Submitting magnet URI to moon-i2p...");
|
||||
const res = await browser.runtime.sendMessage({ type: "addMagnet", uri: parsed.value });
|
||||
if (res && res.ok) {
|
||||
$("nav-input").value = "";
|
||||
setNavMsg(`Added magnet ${(res.info_hash || "").slice(0, 12)}...`);
|
||||
await browser.runtime.sendMessage({ type: "openManager" });
|
||||
} else {
|
||||
setNavMsg(`Magnet failed: ${(res && res.error) || "router offline"}`, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
setNavMsg("");
|
||||
window.location.href = parsed.value;
|
||||
});
|
||||
|
||||
const openManager = () => browser.runtime.sendMessage({ type: "openManager" });
|
||||
$("open-manager-btn").addEventListener("click", openManager);
|
||||
$("torrents-tile").addEventListener("click", openManager);
|
||||
$("open-manager-btn-2").addEventListener("click", openManager);
|
||||
$("open-diag-btn").addEventListener("click", () =>
|
||||
browser.runtime.sendMessage({ type: "openManager", hash: "#diagnostics-card" })
|
||||
);
|
||||
|
||||
$("start-router-btn").addEventListener("click", async () => {
|
||||
setNavMsg("Starting moon-i2p router via native host...");
|
||||
const res = await browser.runtime.sendMessage({ type: "startRouter" });
|
||||
if (res && res.ok) {
|
||||
setNavMsg("Router starting (waiting for API & tunnels)...");
|
||||
} else {
|
||||
setNavMsg(`Failed to start router: ${(res && res.error) || "unavailable"}`, true);
|
||||
}
|
||||
setTimeout(() => refreshStatus(), 700);
|
||||
});
|
||||
|
||||
$("copy-b32-btn").addEventListener("click", async () => {
|
||||
if (!currentB32) {
|
||||
setNavMsg("Router has not published a .b32.i2p address yet.", true);
|
||||
return;
|
||||
}
|
||||
const btn = $("copy-b32-btn");
|
||||
const ok = await copyTextToClipboard(currentB32);
|
||||
if (ok) {
|
||||
btn.textContent = "Copied!";
|
||||
if (copyTimer) clearTimeout(copyTimer);
|
||||
copyTimer = setTimeout(() => {
|
||||
btn.textContent = "Copy .b32";
|
||||
copyTimer = null;
|
||||
}, 1500);
|
||||
} else {
|
||||
setNavMsg("Clipboard copy blocked by browser.", true);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (!document.hidden) {
|
||||
refreshStatus();
|
||||
}
|
||||
});
|
||||
|
||||
refreshStatus();
|
||||
setInterval(() => refreshStatus(), 2000);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user