From e7342828c8d11fb8dd125b544d87af5784236595 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sun, 9 Feb 2025 18:51:02 +0100 Subject: [PATCH] serve javascript from static --- src/public/javascript/index.js | 38 ++++++++++++++++++++++++++++++++++ src/views/index.ejs | 38 +--------------------------------- 2 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 src/public/javascript/index.js 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