diff --git a/src/public/javascript/index.js b/src/public/javascript/index.js new file mode 100644 index 0000000..46188d3 --- /dev/null +++ b/src/public/javascript/index.js @@ -0,0 +1,38 @@ +window.onload = function () { + setTimeout(function () { + console.log("This code runs 2 seconds after the window has loaded."); + const npub = window.nostr.getPublicKey(); + let pubkeyP = document.querySelector("#pubkey-p"); + let pubkeySpan = document.querySelector("#pubkey-span"); + + npub.then(async function (npub) { + console.log(npub); + pubkeyP.style.display = "block"; + pubkeySpan.innerText = npub; + + try { + const response = await fetch('/api/session-npubbed', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + "npub": npub + }) + }); + + if (response.ok) { + const data = await response.json(); + console.log('SessionNpubbed record created successfully:', data); + } else { + const error = await response.json(); + console.error('Failed to create sessionNpubbed record:', error); + } + } catch (error) { + console.error('An error occurred:', error); + } + } + + ) + }, 2000); +} \ No newline at end of file diff --git a/src/views/index.ejs b/src/views/index.ejs index 3448a29..7cbfaff 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -5,6 +5,7 @@ Hello World + @@ -21,44 +22,7 @@ \ No newline at end of file