-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
123 lines (120 loc) · 4.21 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nostr Login</title>
<link
href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css"
rel="stylesheet"
/>
<style>
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #4f86c6, #4aafd7, #64dfdf);
color: #333;
text-align: center;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.button {
background-color: #4aafd7;
color: #fff;
border: none;
padding: 15px 30px;
font-size: 18px;
cursor: pointer;
border-radius: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transition: background-color 0.3s ease, box-shadow 0.3s ease,
transform 0.3s ease;
margin-top: 20px; /* Added margin for better spacing */
}
.button:hover {
background-color: #3791c6;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
transform: translateY(-2px);
}
.button:active {
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
#loginBtn {
display: block;
width: 200px;
margin: 0 auto;
}
</style>
</head>
<body>
<button class="button" id="loginBtn">Login</button>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js"></script>
<script>
const loginButton = document.getElementById('loginBtn')
loginButton.addEventListener('click', function () {
if (loginButton.textContent === 'Login') {
Swal.fire({
title: 'Login to Nostr',
html:
'<p>Choose your login method:</p>' +
'<button class="button" id="extensionBtn">Login with Extension</button>' +
'<p>or enter NSEC/Private Key:</p>' +
'<input type="text" id="nsecInput" class="swal2-input" placeholder="Enter NSEC/Private Key">' +
'<button class="button" id="submitBtn">Submit</button>' +
'<p><a target="_blank" href="https://nostrapps.github.io/extensions/">What is a nostr extension?</a></p>',
showCancelButton: false,
showConfirmButton: false,
preConfirm: () => {
const loginExtension =
Swal.getPopup().querySelector('#extensionBtn')
const submitButton = Swal.getPopup().querySelector('#submitBtn')
const nsecInput =
Swal.getPopup().querySelector('#nsecInput').value
if (loginExtension) {
loginExtension.click()
} else if (submitButton && nsecInput) {
submitButton.click()
}
}
})
} else {
// Handle logout and revert button text to 'Login'
loginButton.textContent = 'Login'
}
})
document.addEventListener('click', async function (e) {
if (e.target.id === 'extensionBtn') {
// Handle the 'Login with Extension' button click
try {
const publicKey = await window.nostr.getPublicKey()
Swal.fire({
icon: 'success',
title: 'Logged in successfully!',
text: 'Your public key is ' + publicKey
})
loginButton.textContent = publicKey.substring(0, 16) // Show first 16 chars of publicKey
} catch (error) {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'An error occurred: ' + error.message
})
}
} else if (e.target.id === 'submitBtn') {
// Handle the 'Submit' button click
const nsecInput = document.getElementById('nsecInput').value
Swal.fire({
icon: 'success',
title: 'Logged in successfully!',
text: 'You have entered: ' + nsecInput
})
loginButton.textContent = nsecInput.substring(0, 16) // Show first 16 chars of NSEC/Private Key
}
})
</script>
</body>
</html>