|
|
|
|
@@ -29,8 +29,44 @@
|
|
|
|
|
<div class="section">
|
|
|
|
|
<h2>Final Event (What gets posted at the end)</h2>
|
|
|
|
|
<div class="input-group">
|
|
|
|
|
<label for="final-content">Message Content:</label>
|
|
|
|
|
<textarea id="final-content" rows="3" placeholder="Enter your message content..."></textarea>
|
|
|
|
|
<div class="tabs">
|
|
|
|
|
<div class="tab active" data-tab="tab1">Post</div>
|
|
|
|
|
<div class="tab" data-tab="tab2">Reply</div>
|
|
|
|
|
<div class="tab" data-tab="tab3">Create Profile</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="tab-content active" id="tab1">
|
|
|
|
|
<h3>Post</h3>
|
|
|
|
|
<label for="final-content">Message Content:</label>
|
|
|
|
|
<textarea id="final-content" rows="3" placeholder="Enter your message content..."></textarea>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tab-content" id="tab2">
|
|
|
|
|
<h3>Reply</h3>
|
|
|
|
|
<label for="nevent">Nevent:</label>
|
|
|
|
|
<textarea id="nevent" placeholder="Enter the nevent for the note..."></textarea>
|
|
|
|
|
<label for="reply-content">Message Content:</label>
|
|
|
|
|
<textarea id="reply-content" rows="3" placeholder="Enter your message content..."></textarea>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="tab-content" id="tab3">
|
|
|
|
|
<h3>Create Profile</h3>
|
|
|
|
|
<label for="name">Name:</label>
|
|
|
|
|
<textarea id="name" placeholder="Enter your name..."></textarea>
|
|
|
|
|
<label for="about">About:</label>
|
|
|
|
|
<textarea id="about" rows="2" placeholder="A short bio..."></textarea>
|
|
|
|
|
<label for="profile-pic">Profile Picture:</label>
|
|
|
|
|
<textarea id="profile-pic" placeholder="URL of your profile pic..."></textarea>
|
|
|
|
|
<label for="display-name">Display Name:</label>
|
|
|
|
|
<textarea id="display-name" placeholder="Enter your display name..."></textarea>
|
|
|
|
|
<label for="website">Website:</label>
|
|
|
|
|
<textarea id="website" placeholder="Web URL..."></textarea>
|
|
|
|
|
<label for="banner">Banner:</label>
|
|
|
|
|
<textarea id="banner" placeholder="Enter your bannerm a (~1024x768) wide picture url..."></textarea>
|
|
|
|
|
<label for="nip05">NIP05:</label>
|
|
|
|
|
<textarea id="nip05" placeholder="Enter your nip05 in the format username@domain.com..."></textarea>
|
|
|
|
|
<label for="lud16">Lightning Address:</label>
|
|
|
|
|
<textarea id="lud16" placeholder="Enter your lightning address..."></textarea>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<button onclick="createFinalEvent()">Create Event That Will Be Published Publicly</button>
|
|
|
|
|
|
|
|
|
|
@@ -79,6 +115,26 @@
|
|
|
|
|
<!-- <script src="./nostr-lite.js"></script> -->
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
const tabs = document.querySelectorAll('.tab');
|
|
|
|
|
const tabContents = document.querySelectorAll('.tab-content');
|
|
|
|
|
|
|
|
|
|
tabs.forEach(tab => {
|
|
|
|
|
tab.addEventListener('click', () => {
|
|
|
|
|
// Remove active class from all tabs and contents
|
|
|
|
|
tabs.forEach(t => t.classList.remove('active'));
|
|
|
|
|
tabContents.forEach(c => c.classList.remove('active'));
|
|
|
|
|
|
|
|
|
|
// Add active class to clicked tab
|
|
|
|
|
tab.classList.add('active');
|
|
|
|
|
|
|
|
|
|
// Show corresponding content
|
|
|
|
|
const tabId = tab.getAttribute('data-tab');
|
|
|
|
|
document.getElementById(tabId).classList.add('active');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
// Global variables
|
|
|
|
|
let nlLite = null;
|
|
|
|
|
let userPubkey = null;
|
|
|
|
|
@@ -232,7 +288,11 @@
|
|
|
|
|
} else {
|
|
|
|
|
console.log('INFO', 'No relay list found, using defaults');
|
|
|
|
|
userRelays = [
|
|
|
|
|
{ url: 'wss://relay.laantungir.net', type: 'both' }
|
|
|
|
|
{ url: 'wss://relay.laantungir.net', type: 'both' },
|
|
|
|
|
{ url: 'wss://relay.primal.net', type: 'both' },
|
|
|
|
|
{ url: 'wss://nos.lol', type: 'both' },
|
|
|
|
|
{ url: 'wss://relay.damus.io', type: 'both' },
|
|
|
|
|
{ url: 'wss://offchain.pub', type: 'both' }
|
|
|
|
|
];
|
|
|
|
|
return userRelays;
|
|
|
|
|
}
|
|
|
|
|
@@ -712,22 +772,118 @@
|
|
|
|
|
|
|
|
|
|
// Create final event (kind 1)
|
|
|
|
|
async function createFinalEvent() {
|
|
|
|
|
const content = document.getElementById('final-content').value.trim();
|
|
|
|
|
// Get the active tab
|
|
|
|
|
const activeTab = document.querySelector('.tab.active').getAttribute('data-tab');
|
|
|
|
|
|
|
|
|
|
// Get content based on active tab
|
|
|
|
|
let content = '';
|
|
|
|
|
let nevent = '';
|
|
|
|
|
let neventData;
|
|
|
|
|
let name = '';
|
|
|
|
|
let about = '';
|
|
|
|
|
let profilePic = '';
|
|
|
|
|
let displayName = '';
|
|
|
|
|
let website = '';
|
|
|
|
|
let banner = '';
|
|
|
|
|
let nip05 = '';
|
|
|
|
|
let lud16 = '';
|
|
|
|
|
|
|
|
|
|
switch(activeTab) {
|
|
|
|
|
case 'tab1': // Post
|
|
|
|
|
content = document.getElementById('final-content').value.trim();
|
|
|
|
|
break;
|
|
|
|
|
case 'tab2': // Reply
|
|
|
|
|
content = document.getElementById('reply-content').value.trim();
|
|
|
|
|
nevent = document.getElementById('nevent').value.trim();
|
|
|
|
|
break;
|
|
|
|
|
case 'tab3': // Create Profile
|
|
|
|
|
name = document.getElementById('name').value.trim();
|
|
|
|
|
about = document.getElementById('about').value.trim();
|
|
|
|
|
profilePic = document.getElementById('profile-pic').value.trim();
|
|
|
|
|
displayName = document.getElementById('display-name').value.trim();
|
|
|
|
|
website = document.getElementById('website').value.trim();
|
|
|
|
|
banner = document.getElementById('banner').value.trim();
|
|
|
|
|
nip05 = document.getElementById('nip05').value.trim();
|
|
|
|
|
lud16 = document.getElementById('lud16').value.trim();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!content) {
|
|
|
|
|
alert('Please enter message content');
|
|
|
|
|
return;
|
|
|
|
|
// Validate content based on tab
|
|
|
|
|
if (activeTab === 'tab1') {
|
|
|
|
|
if (!content) {
|
|
|
|
|
alert('Please enter message content');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else if (activeTab === 'tab2') {
|
|
|
|
|
if (!content) {
|
|
|
|
|
alert('Please enter message content');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!nevent.startsWith('nevent')) {
|
|
|
|
|
alert('Please enter a valid nevent');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
neventData = window.NostrTools.nip19.decode(nevent).data;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
alert('Error decoding nevent string', error.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else if (activeTab === 'tab3') {
|
|
|
|
|
if (!name) {
|
|
|
|
|
alert('Please enter your name');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Create the final event (kind 1) - pure message, no relay info
|
|
|
|
|
const eventTemplate = {
|
|
|
|
|
kind: 1,
|
|
|
|
|
content: content,
|
|
|
|
|
tags: [],
|
|
|
|
|
created_at: Math.floor(Date.now() / 1000)
|
|
|
|
|
};
|
|
|
|
|
let eventTemplate = {};
|
|
|
|
|
|
|
|
|
|
switch(activeTab) {
|
|
|
|
|
case 'tab1': // Post
|
|
|
|
|
eventTemplate = {
|
|
|
|
|
kind: 1,
|
|
|
|
|
content: content,
|
|
|
|
|
tags: [],
|
|
|
|
|
created_at: Math.floor(Date.now() / 1000)
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'tab2': // Reply
|
|
|
|
|
eventTemplate = {
|
|
|
|
|
kind: 1,
|
|
|
|
|
content: content,
|
|
|
|
|
tags: [['e', neventData.id, neventData.relays[0], 'root'], ['p', neventData.author]],
|
|
|
|
|
created_at: Math.floor(Date.now() / 1000)
|
|
|
|
|
};
|
|
|
|
|
neventData.relays.slice(1).forEach(relay => {
|
|
|
|
|
eventTemplate.tags.push(['r', relay]);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'tab3': // Create Profile
|
|
|
|
|
eventTemplate = {
|
|
|
|
|
kind: 0,
|
|
|
|
|
content: JSON.stringify({
|
|
|
|
|
name: name,
|
|
|
|
|
about: about,
|
|
|
|
|
picture: profilePic,
|
|
|
|
|
display_name: displayName,
|
|
|
|
|
website: website,
|
|
|
|
|
banner: banner,
|
|
|
|
|
nip05: nip05,
|
|
|
|
|
lud16: lud16
|
|
|
|
|
}),
|
|
|
|
|
tags: [],
|
|
|
|
|
created_at: Math.floor(Date.now() / 1000)
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Your existing event publishing logic here
|
|
|
|
|
console.log('Event to publish:', eventTemplate);
|
|
|
|
|
// ... rest of your publishing code
|
|
|
|
|
|
|
|
|
|
// Sign the event using window.nostr (NIP-07)
|
|
|
|
|
finalEvent = await window.nostr.signEvent(eventTemplate);
|
|
|
|
|
|
|
|
|
|
|