301 lines
11 KiB
HTML
301 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>NDK Tab Test v1.0.7</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background: #f5f5f5;
|
|
}
|
|
.header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.card {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin: 15px 0;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
#status {
|
|
padding: 15px;
|
|
margin: 20px 0;
|
|
border-radius: 8px;
|
|
font-weight: bold;
|
|
}
|
|
.loading { background: #fff3cd; color: #856404; }
|
|
.success { background: #d4edda; color: #155724; }
|
|
.error { background: #f8d7da; color: #721c24; }
|
|
.info { background: #d1ecf1; color: #0c5460; }
|
|
.relay-list {
|
|
list-style: none;
|
|
padding: 0;
|
|
}
|
|
.relay-list li {
|
|
padding: 10px;
|
|
margin: 5px 0;
|
|
background: #e9ecef;
|
|
border-radius: 4px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
.relay-list li.connected {
|
|
background: #d4edda;
|
|
border-left: 4px solid #28a745;
|
|
}
|
|
.relay-list li.disconnected {
|
|
background: #f8d7da;
|
|
border-left: 4px solid #dc3545;
|
|
}
|
|
.badge {
|
|
padding: 4px 8px;
|
|
border-radius: 4px;
|
|
font-size: 0.85em;
|
|
font-weight: bold;
|
|
}
|
|
.badge.connected {
|
|
background: #28a745;
|
|
color: white;
|
|
}
|
|
.badge.disconnected {
|
|
background: #dc3545;
|
|
color: white;
|
|
}
|
|
button {
|
|
background: #667eea;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 1em;
|
|
}
|
|
button:hover {
|
|
background: #5568d3;
|
|
}
|
|
.log {
|
|
background: #f8f9fa;
|
|
padding: 10px;
|
|
border-radius: 4px;
|
|
font-family: monospace;
|
|
font-size: 0.9em;
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
margin-top: 10px;
|
|
}
|
|
.log-entry {
|
|
padding: 2px 0;
|
|
border-bottom: 1px solid #dee2e6;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>🔗 NDK Multi-Tab Test</h1>
|
|
<p style="margin: 5px 0;">Version 0.0.7 (2026-01-30) - Dexie Cache - Tab Instance</p>
|
|
<p style="margin: 5px 0; font-size: 0.9em; opacity: 0.9;">
|
|
This page connects to the existing SharedWorker to demonstrate multi-tab functionality
|
|
</p>
|
|
</div>
|
|
|
|
<div id="status" class="loading">Connecting to SharedWorker...</div>
|
|
|
|
<div class="card">
|
|
<h3>📊 Worker Status</h3>
|
|
<p><strong>Worker Version:</strong> <span id="worker-version">Unknown</span></p>
|
|
<p><strong>Connection Status:</strong> <span id="connection-status">Connecting...</span></p>
|
|
<p><strong>Current User:</strong> <span id="user-pubkey">Not loaded</span></p>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h3>👤 User Profile</h3>
|
|
<p><strong>Name:</strong> <span id="user-name">Loading...</span></p>
|
|
<p><strong>About:</strong> <span id="user-about">Loading...</span></p>
|
|
<p><strong>NIP-05:</strong> <span id="user-nip05">Loading...</span></p>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h3>🌐 Connected Relays</h3>
|
|
<p id="relay-count">Loading relay information...</p>
|
|
<ul id="relay-list" class="relay-list"></ul>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h3>📝 Event Log</h3>
|
|
<div id="event-log" class="log"></div>
|
|
<button onclick="clearLog()">Clear Log</button>
|
|
</div>
|
|
|
|
<script>
|
|
// App state
|
|
let sharedWorker = null;
|
|
const eventLog = [];
|
|
|
|
// UI elements
|
|
const statusDiv = document.getElementById('status');
|
|
const workerVersionSpan = document.getElementById('worker-version');
|
|
const connectionStatusSpan = document.getElementById('connection-status');
|
|
const userPubkeySpan = document.getElementById('user-pubkey');
|
|
const userNameSpan = document.getElementById('user-name');
|
|
const userAboutSpan = document.getElementById('user-about');
|
|
const userNip05Span = document.getElementById('user-nip05');
|
|
const relayCountP = document.getElementById('relay-count');
|
|
const relayListUl = document.getElementById('relay-list');
|
|
const eventLogDiv = document.getElementById('event-log');
|
|
|
|
// Log event
|
|
function logEvent(message, type = 'info') {
|
|
const timestamp = new Date().toLocaleTimeString();
|
|
const entry = `[${timestamp}] ${message}`;
|
|
eventLog.push(entry);
|
|
|
|
const logEntry = document.createElement('div');
|
|
logEntry.className = 'log-entry';
|
|
logEntry.textContent = entry;
|
|
eventLogDiv.appendChild(logEntry);
|
|
eventLogDiv.scrollTop = eventLogDiv.scrollHeight;
|
|
|
|
console.log(entry);
|
|
}
|
|
|
|
// Clear log
|
|
function clearLog() {
|
|
eventLog.length = 0;
|
|
eventLogDiv.innerHTML = '';
|
|
}
|
|
|
|
// Update status message
|
|
function setStatus(message, type = 'loading') {
|
|
statusDiv.textContent = message;
|
|
statusDiv.className = type;
|
|
logEvent(`Status: ${message}`);
|
|
}
|
|
|
|
// Update user profile display
|
|
function updateUserProfile(profile) {
|
|
logEvent('Received profile update');
|
|
|
|
if (profile.name) {
|
|
userNameSpan.textContent = profile.name;
|
|
}
|
|
if (profile.display_name) {
|
|
userNameSpan.textContent = profile.display_name;
|
|
}
|
|
if (profile.about) {
|
|
userAboutSpan.textContent = profile.about;
|
|
}
|
|
if (profile.nip05) {
|
|
userNip05Span.textContent = profile.nip05;
|
|
}
|
|
}
|
|
|
|
// Update relay list display
|
|
function updateRelayList(relays) {
|
|
logEvent(`Received relay list: ${relays.length} relays`);
|
|
|
|
const connectedCount = relays.filter(r => r.connected).length;
|
|
relayCountP.textContent = `${connectedCount} of ${relays.length} relays connected`;
|
|
|
|
relayListUl.innerHTML = '';
|
|
relays.forEach(relay => {
|
|
const li = document.createElement('li');
|
|
li.className = relay.connected ? 'connected' : 'disconnected';
|
|
|
|
const urlSpan = document.createElement('span');
|
|
urlSpan.textContent = relay.url;
|
|
|
|
const badge = document.createElement('span');
|
|
badge.className = `badge ${relay.connected ? 'connected' : 'disconnected'}`;
|
|
badge.textContent = relay.connected ? 'Connected' : 'Disconnected';
|
|
|
|
li.appendChild(urlSpan);
|
|
li.appendChild(badge);
|
|
relayListUl.appendChild(li);
|
|
});
|
|
}
|
|
|
|
// Initialize SharedWorker connection
|
|
function initSharedWorker() {
|
|
logEvent('Initializing SharedWorker connection...');
|
|
|
|
try {
|
|
sharedWorker = new SharedWorker('ndk-worker.js');
|
|
|
|
// Listen for messages from worker
|
|
sharedWorker.port.onmessage = (event) => {
|
|
const { type, data } = event.data;
|
|
logEvent(`Worker message: ${type}`);
|
|
|
|
switch(type) {
|
|
case 'ready':
|
|
connectionStatusSpan.textContent = 'Connected';
|
|
connectionStatusSpan.style.color = '#28a745';
|
|
setStatus('Connected to SharedWorker', 'success');
|
|
break;
|
|
|
|
case 'profile':
|
|
updateUserProfile(data);
|
|
break;
|
|
|
|
case 'relays':
|
|
updateRelayList(data);
|
|
setStatus('Relay information received', 'success');
|
|
break;
|
|
|
|
case 'error':
|
|
setStatus(`Error: ${data.message}`, 'error');
|
|
break;
|
|
}
|
|
};
|
|
|
|
sharedWorker.port.onerror = (error) => {
|
|
logEvent(`Worker error: ${error.message}`, 'error');
|
|
setStatus('SharedWorker error', 'error');
|
|
};
|
|
|
|
// Start the port
|
|
sharedWorker.port.start();
|
|
|
|
// Check if there's an existing session
|
|
const savedPubkey = localStorage.getItem('nostr_pubkey');
|
|
if (savedPubkey) {
|
|
logEvent(`Found existing session: ${savedPubkey.substring(0, 16)}...`);
|
|
userPubkeySpan.textContent = savedPubkey;
|
|
|
|
// Initialize worker with user pubkey
|
|
sharedWorker.port.postMessage({
|
|
type: 'init',
|
|
pubkey: savedPubkey
|
|
});
|
|
} else {
|
|
setStatus('No active session found. Please log in via index.html first.', 'info');
|
|
connectionStatusSpan.textContent = 'No Session';
|
|
connectionStatusSpan.style.color = '#856404';
|
|
}
|
|
|
|
} catch (error) {
|
|
logEvent(`Failed to initialize SharedWorker: ${error.message}`, 'error');
|
|
setStatus(`SharedWorker error: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Initialize on load
|
|
window.addEventListener('load', () => {
|
|
logEvent('Page loaded, starting initialization...');
|
|
workerVersionSpan.textContent = '1.0.7';
|
|
initSharedWorker();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|